Design Tinder (Dating App)
medium 60 minShow people nearby, record a yes or a no, and tell both when the yes is mutual.
See it run
A swipe, a mutual like, a deck and a map, one hop at a time. Then the moments when a match could be lost.
Operations
A like without a match
The phone never waits for the next card. The server writes the like, then looks at the pair.
Step 1 of 11
Swipe right
action
like
target
Noor
A member likes a profile. One quick gesture is the whole question.
Step 1: Swipe right
def like(me, other): key = tuple(sorted((me, other))) likes.put(key, me, level="QUORUM") # same key, safe to repeat rows = likes.get(key, level="QUORUM") if len(rows) == 2: return announce(key) return {"match": False}- Latency
- under 100 ms at p99
- Load
- 35,000/s at peak
- row
- 50 B
Say the order: write, then read.
In the real world
The same dating app doing real jobs. Pick one and step through it.
Three copies, quorum of two. Follow the copy that both requests share.
Step 1 of 4
Sam writes
Copies 1 and 2 confirm Sam's row.
Step 1: Sam writes
Common mistakes
The bugs interviewers watch for, with the fix beside each.
Reading before writing
criticalTwo simultaneous requests both see nothing. Two likes, no match, no error.
Wrongfound = has_liked(other, me)store_like(me, other)if found: make_match()Rightstore_like(me, other) # quorumif both_liked(me, other): # quorum make_match_if_absent()A local quorum across regions
criticalThe copies asked by each side need not overlap.
Wrongstore.put(key, me, "LOCAL_QUORUM") # own regionRightregion = home(key) # same for bothstores[region].put(key, me, "LOCAL_QUORUM")Rebuilding every deck on a timer
majorTen million decks in 900 seconds is 11,100 a second. Most are never looked at.
Wrongevery(15 * MINUTE, build_all_decks)Rightif cards_left(member) <= 20: build_deck_in_background(member)Sending exact distances
criticalThree distances from three places fix a point.
Wrongreturn {"km": 0.4127}Rightreturn {"distance": "less than 2 km"}A like list that cannot be searched
majorKeyed by time, the question "has this person been swiped?" scans the partition.
WrongPRIMARY KEY ((member), swiped_at)RightPRIMARY KEY ((member, month), target)
Interview tips
Lead with the promise
- "Two likes, one match, always."
- Write, then read, in one place.
- Computed id, created if absent.
Numbers that decide
- 35,000 swipes a second at peak.
- 18 GPUs on demand against 556 on a timer.
- 167 Gb/s of photos at peak.
Anticipate failures
- Push late: sync on opening.
- Model down: nearest first.
- Two copies down: wait, do not lower the level.
Protect people
- Round distances on the server.
- Check blocks when cards are sent.
- Reports reach a person.