AlgoViz

Design Tinder (Dating App)

medium 60 min

Show 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

Our systemPhone appGatewaySwipe svcDeck svcCassandralikes by pair

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

Our systemSam's requestNoor's requestCopy 1Copy 2Copy 3

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

    critical

    Two simultaneous requests both see nothing. Two likes, no match, no error.

    Wrong
    found = has_liked(other, me)store_like(me, other)if found: make_match()
    Right
    store_like(me, other)       # quorumif both_liked(me, other):   # quorum    make_match_if_absent()
  • A local quorum across regions

    critical

    The copies asked by each side need not overlap.

    Wrong
    store.put(key, me, "LOCAL_QUORUM")  # own region
    Right
    region = home(key)          # same for bothstores[region].put(key, me, "LOCAL_QUORUM")
  • Rebuilding every deck on a timer

    major

    Ten million decks in 900 seconds is 11,100 a second. Most are never looked at.

    Wrong
    every(15 * MINUTE, build_all_decks)
    Right
    if cards_left(member) <= 20:    build_deck_in_background(member)
  • Sending exact distances

    critical

    Three distances from three places fix a point.

    Wrong
    return {"km": 0.4127}
    Right
    return {"distance": "less than 2 km"}
  • A like list that cannot be searched

    major

    Keyed by time, the question "has this person been swiped?" scans the partition.

    Wrong
    PRIMARY KEY ((member), swiped_at)
    Right
    PRIMARY 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.