#49 Proximity Search/Scoring
Tinder Matching
Show each user a stack of nearby profiles they have not seen, ranked by likely mutual interest, and detect a match the moment both swipe right.
What is being asked
Design the recommendation and matching core of a dating app: generate a deck of candidate profiles for a user, record swipes at high volume, and notify both people when the interest is mutual.
Requirements
Functional
- Serve a deck of profiles filtered by distance, age and preferences.
- Record left and right swipes; create a match on mutual right swipes.
- Never show a profile the user has already swiped.
Non-functional
- Enormous swipe volume, far more writes than matches.
- Decks must feel instant.
- Location changes as people move.
Design
- Profiles are indexed by location cell, and the index is sharded geographically so a query touches only the shards covering the user's search radius.
- The recommendation service retrieves candidates matching the filters, removes those in the user's seen-set, ranks the rest and returns a deck of a few dozen, cached for the session.
- A swipe is written to a store keyed by (swiper, target).
- On a right swipe, the match service checks whether the reverse right swipe exists. If so it creates the match and notifies both.
Key decisions and trade-offs
- Geographic sharding keeps queries local, since nobody is matched across continents. Dense cities need smaller cells than rural areas.
- The seen-set grows without limit. A Bloom filter per user answers "have I seen this profile" in little memory; its rare false positives only hide a profile.
- Checking for a match. Looking up the reverse swipe on each right swipe is a single key read; two simultaneous right swipes must still produce exactly one match, which a unique key on the ordered pair guarantees.
- Ranking objective. Ranking by attractiveness alone concentrates attention on few profiles; ranking by probability of a mutual like spreads it.
Follow-up questions
- How do you treat a user who travels to another city?
- What do you do when someone runs out of profiles nearby?
- How would you detect fake or automated accounts from swipe patterns?
- How does "undo last swipe" work with this storage?