Designing a Temporary Activity-Partner Matching System: Data Model, Matching Strategy, Lifecycle, and Risk Governance

    Temporary activity partners are people who agree to do a specific activity together—such as a meal, workout, or trip—around a shared interest or time window. These relationships are goal-limited and carry no fixed obligations. This article presents an engineering-oriented design for matching and managing such relationships. It defines three computable constraints: vertical domain, limited goal, and time boundary. It then describes a data model for user profiles and partner pairs, a two-stage matching strategy that combines inverted-index recall with tag, time, and region scoring, and a state-machine-based lifecycle for confirmation, completion, expiry, and cancellation. The article also covers boundary control and risk governance, including detection of paid companionship, rate limits, credit and reporting signals, and privacy and offline safety measures. It ends with observability metrics for evaluating matching precision, completion behavior, and early cancellation.

    I. Background and Problem Definition

    A temporary activity partner refers to a short-term companionship relationship formed around a specific interest, moment, or scenario. Its level of intimacy sits between that of friends and colleagues, and it carries no fixed relationship obligations. A meal partner agrees on the same meal; a fitness partner agrees on the same training slot; a travel partner agrees on the same itinerary. For product developers, the value of this relationship model lies in its clear objective, low cost, and ability to end at any time.

    There are three common problems when implementing this type of feature.

    The first is low matching precision. Recommending only by geographic location or age often produces candidates who do not match the user’s real needs, causing users to ignore recommendation results frequently.

    The second is blurred boundaries. The relationship has no clear termination mechanism, making it difficult for users to exit gracefully and potentially causing psychological pressure.

    The third is risk exposure. When temporary activity partners are used for paid companionship or paid group organizing, a lack of platform governance rules can lead to disputes and may also create personal safety issues.

    This article breaks down these problems from an engineering perspective and provides reference approaches for the data model, matching strategy, lifecycle management, and risk governance. All weights, thresholds, and other numeric values in this article are examples; actual values need to be tuned against business data.

    II. Abstracting the Core Characteristics

    A temporary activity-partner relationship can be abstracted into three computable constraints.

    1. Vertical domain: Each relationship is bound to an explicit interest or scenario tag, such as “morning run,” “Sichuan cuisine,” or “weekend hiking.” The tag is the primary basis for matching and the reason the relationship exists.
    2. Limited goal: Each relationship has an explicit goal and termination condition, such as “complete three workouts this week” or “complete one trip.” Once the goal is achieved, the relationship naturally ends.
    3. Time boundary: Each relationship has a start and end time. After the time window expires, the relationship is automatically dissolved or enters an optional renewal process for both parties.

    These three constraints determine the main direction of the system design. Matching needs to find the intersection of tags and time windows; relationships need a state machine to manage their lifecycle; and when a relationship ends, neither party should need to explain why, nor should the system require an explanation.

    III. Data Model Design

    The following data model covers both user profiles and relationship entities.

    1. from dataclasses import dataclass, field
    2. from datetime import datetime, timezone
    3. from enum import Enum
    4. class PairStatus(Enum):
    5. PENDING = "pending" # Initiated, awaiting confirmation
    6. ACTIVE = "active" # Confirmed by both parties, relationship is active
    7. COMPLETED = "completed" # Goal achieved, ended normally
    8. EXPIRED = "expired" # Time window exceeded, ended automatically
    9. CANCELLED = "cancelled" # Cancelled by either party
    10. @dataclass
    11. class PartnerProfile:
    12. user_id: str
    13. tags: set[str] # Interest or scenario tags
    14. availability: list[tuple[datetime, datetime]] # Available time slots; should not overlap
    15. region: str # Coarse-grained region, such as city or district
    16. max_active_pairs: int = 3 # Maximum number of simultaneously active relationships
    17. @dataclass
    18. class PartnerPair:
    19. pair_id: str
    20. user_a: str
    21. user_b: str
    22. scene_tag: str
    23. window_start: datetime
    24. window_end: datetime
    25. goal: str # Textual description of the limited goal
    26. status: PairStatus = PairStatus.PENDING
    27. created_at: datetime = field(
    28. default_factory=lambda: datetime.now(timezone.utc)
    29. )

    Several fields are designed for the following reasons.

    • region stores only a coarse-grained region and does not store precise location, reducing privacy exposure.
    • availability is used only during the matching phase; users do not need to display their complete schedule externally.
    • max_active_pairs limits the number of relationships a single user can have at the same time, preventing relationship accumulation and avoiding excessive time occupation by temporary activity-partner relationships.
    • goal is required and must contain a textual description. The clarity of the goal directly reflects the limited-commitment characteristic.

    IV. Matching Strategy

    Matching is divided into two steps: candidate recall and fine-grained scoring.

    4.1 Candidate Recall

    Calculating all pairwise matches is too expensive. In practice, inverted indexes are built for tags and regions. Candidates are first recalled by “same region and at least one shared tag,” and then enter the scoring phase. The recall phase does not calculate time because time matching has a higher computational cost and should be placed later.

    4.2 Scoring Function

    The scoring function consists of three parts: tag similarity, time overlap, and region consistency.

    1. def jaccard(a: set[str], b: set[str]) -> float:
    2. """Jaccard similarity between tag sets, in the range [0, 1]."""
    3. if not a or not b:
    4. return 0.0
    5. return len(a & b) / len(a | b)
    6. def overlap_hours(
    7. slots_a: list[tuple[datetime, datetime]],
    8. slots_b: list[tuple[datetime, datetime]],
    9. ) -> float:
    10. """Calculate the total overlap duration in hours between two sets of time slots.
    11. Assumes that time slots within each set do not overlap; otherwise,
    12. durations will be double-counted.
    13. """
    14. total = 0.0
    15. for a_start, a_end in slots_a:
    16. for b_start, b_end in slots_b:
    17. start = max(a_start, b_start)
    18. end = min(a_end, b_end)
    19. if end > start:
    20. total += (end - start).total_seconds() / 3600
    21. return total
    22. def match_score(
    23. x: PartnerProfile,
    24. y: PartnerProfile,
    25. min_hours: float = 1.0,
    26. full_hours: float = 4.0,
    27. ) -> float:
    28. """Return the match score between two users; 0 means no match."""
    29. if x.region != y.region:
    30. return 0.0
    31. tag_score = jaccard(x.tags, y.tags)
    32. if tag_score == 0.0:
    33. return 0.0
    34. hours = overlap_hours(x.availability, y.availability)
    35. if hours < min_hours:
    36. return 0.0
    37. # Once the overlap reaches full_hours, cap the time score at 1
    38. time_score = min(hours / full_hours, 1.0)
    39. return 0.7 * tag_score + 0.3 * time_score

    The design notes are as follows.

    • Hard filtering comes first: Different regions, no shared tags, and insufficient time overlap all return 0 directly. Hard filtering reduces unnecessary computation and ensures that recommendation results meet the most basic feasibility conditions.
    • Tag weight is higher than time weight: Shared interests are the prerequisite for a temporary activity-partner relationship. Inconvenient time can be adjusted, but inconsistent interests cannot form stable companionship. Therefore, the tag weight is set to 0.7. This value is only an example.
    • Time score is capped: Beyond a certain duration, additional overlap contributes limited improvement to match quality. Capping prevents users with long available time slots from gaining an excessive ranking advantage.

    4.3 Tag Normalization

    Tag quality directly affects matching performance. Common practices include building a tag dictionary and normalizing capitalization and full-width/half-width characters; merging synonyms in user input, for example, mapping “running” and “jogging” to the same tag; and limiting the number of tags per user to prevent tag stuffing from distorting similarity.

    V. Relationship Lifecycle Management

    Relationships need to be described by a state machine; otherwise, concurrent operations can easily produce illegal states, such as reactivating an expired relationship.

    1. ALLOWED_TRANSITIONS: dict[PairStatus, set[PairStatus]] = {
    2. PairStatus.PENDING: {
    3. PairStatus.ACTIVE,
    4. PairStatus.CANCELLED,
    5. PairStatus.EXPIRED,
    6. },
    7. PairStatus.ACTIVE: {
    8. PairStatus.COMPLETED,
    9. PairStatus.EXPIRED,
    10. PairStatus.CANCELLED,
    11. },
    12. # COMPLETED, EXPIRED, and CANCELLED are terminal states; no further transitions are allowed
    13. }
    14. def transition(pair: PartnerPair, target: PairStatus) -> PartnerPair:
    15. allowed = ALLOWED_TRANSITIONS.get(pair.status, set())
    16. if target not in allowed:
    17. raise ValueError(
    18. f"Invalid state transition: {pair.status.value} -> {target.value}"
    19. )
    20. pair.status = target
    21. return pair

    The main relationship flows are as follows.

    1. One party initiates, and the relationship enters PENDING.
    2. The other party confirms, and the relationship enters ACTIVE. If the other party rejects or does not respond before the timeout, the relationship enters CANCELLED or EXPIRED.
    3. Both parties complete the goal within the window, and the relationship enters COMPLETED.
    4. If the window ends without completion, the relationship enters EXPIRED.

    Expiration processing requires a scheduled job. The job periodically scans ACTIVE relationships whose window_end is earlier than the current time and transitions them to EXPIRED. Every state transition should be written to an audit log, recording the operator, time, and previous state for dispute investigation.

    VI. Boundary Control and Risk Governance

    The boundary issue of the temporary activity-partner model is both a product issue and a compliance issue. The following measures can serve as a baseline approach.

    6.1 Identifying Paid Companionship and Paid Group Organizing

    The core characteristic of paid companionship is a direct link between service and compensation. The system can identify risk at two levels.

    • Text layer: Apply keyword and semantic classification to initiation content and direct messages to identify quotes, payment on behalf, hourly charges, and similar expressions. When a match is found, route the case to manual review instead of banning directly, to reduce false positives.
    • Transaction layer: Do not allow relationship parties to direct funds off-platform. Paid group activities should be required to use a traceable formal transaction process, and organizers should undergo qualification verification.

    6.2 Rate Limits and Quotas

    • Limit the number of match initiations per user per day to prevent mass solicitation or abuse by automated scripts.
    • Use max_active_pairs to limit the number of simultaneous relationships and prevent users from being passively drawn into multiple relationships.
    • Apply a cooldown limit to repeated short-term initiations between the same pair of users.

    6.3 Credit Records and Reports

    Record completion rate, cancellation rate, and reports as auxiliary signals for matching ranking. Two points need attention. First, cancellation is a normal operation and should not be treated directly as negative behavior; only high-frequency anomalies such as “unreasonable cancellation near the start of the window” may be counted. Second, credit scores must not be tied to personal character evaluation; they should be used only to assess platform risk.

    6.4 Privacy and Offline Safety

    • Display region information only down to the district level, not precise location.
    • Use time slots only for matching calculation and do not externally display a complete schedule.
    • For offline meeting scenarios, recommend public places by default and display basic safety tips.
    • Provide a one-click reporting entry point and a quick path to end a relationship; ending a relationship should not require a reason.

    VII. Observability and Evaluation Metrics

    After launch, the following metrics need to be continuously observed to determine whether the approach is effective.

    Metric Meaning Purpose
    Match acceptance rate Share of recommended users who agree to confirm Evaluate matching precision
    Relationship completion rate Number of COMPLETED relationships as a share of active relationships Evaluate whether goal setting is reasonable
    Early cancellation rate Share of ACTIVE relationships cancelled voluntarily —