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.

Video lesson · Chapter 1 of 5

One swipe and no match

0:00 / 3:40

Theory

Read or listen first. About 2 min.

What it is

A dating app like Tinder shows one profile at a time. The member says yes (a like) or no (a pass). When two members have each said yes to the other, that is a match, and only then can they write to each other.

Behind that gesture are three systems: one that picks whom to show (the deck), one that records answers and finds matches, and one that delivers matches and messages. They have different loads and need different promises.

Why it exists

The swipe turns a long profile search into one quick question. It also hides a no: nobody learns that they were passed, which is why the server, not the phone, must keep likes and compare them.

It is a good interview problem because the easy parts are large and the hard part is small. A billion swipes a day is only disk and partitions. Never missing a mutual like is a question about ordering, and many fast designs get it wrong.

A short history

  1. 1960

    The US Chess Federation adopts Arpad Elo's rating system, later borrowed for ranking in many other fields.

  2. 2008

    Gustavo Niemeyer publishes geohash, which turns a latitude and longitude into a short string.

  3. 2012

    Tinder launches after a hackathon prototype called Matchbox.

  4. 2019 and later

    Tinder says on its own site that Elo is "old news" and that its matching no longer relies on it.

Words to know

Deck
The ordered list of profiles a member will be shown next.
Like and pass
A yes and a no. A super like is a yes that the other person is told about.
Match
Both members of a pair have liked each other.
Pair key
The two member ids in a fixed order, so both sides compute the same key.
Geohash
A code for a rectangle on the map. Adding a letter makes the rectangle smaller.
Bloom filter
A small memory structure that says "certainly not seen" or "probably seen".
Quorum
A majority of copies. A quorum write and a quorum read of the same copies always share at least one.

Solve it like an interview

New to it? Start with Approach. Revising? Go straight to the mock.

  1. 1ApproachWhat this question tests, where it gets hard, and how to spend the time.
  2. 2ScopeAsk what changes the design, then commit to a short list.
  3. 3NumbersWork out a number when the answer changes what you build.
  4. 4API and dataThe contract first, then the data that serves it.
  5. 5DesignStart with the smallest system that works. Change it only when something breaks.
  6. 6Deep divesCompare the options before you open them, then say which you would pick.
  7. 7Explain your choicesAnswer first. Then compare your reasoning.
  8. 8By levelThe same question is judged differently for mid, senior and staff.
  9. 9MockAnswer against the clock, then score yourself.

How it works

Step through the idea, or press Play.

Step 1 of 3

Build a deck. People nearby who fit both sides' wishes and have not been seen

Understand it

The dance with colour cards
BOARDSamNoorSam + Noor

Scope

What are we building?

A service like Tinder: profiles with photos, a deck of people nearby, like and pass, matches, and a chat that opens after a match. This page is an exercise inspired by well-known products. It does not describe any company's real system.

Similar applications

ServiceKnown for
BumbleTime-limited matches
HingeProfiles built from prompts
OkCupidCompatibility from questions
GrindrLocation first, quick messages
Coffee Meets BagelA small daily selection
HappnPeople whose paths you crossed
The same three systems appear in each; the rules between like and chat differ.

The hard part

Never lose a mutual like

Suppose both people press like in the same instant. If each request first asks "did the other one like me?" and then writes, both can be told no. Two likes are stored and no match ever appears. Nobody sees an error, so nobody reports it.

Read first: the match is lost

Reversing the order, write and then read, removes the gap as long as both requests use the same copies.

The finished system

Where the design ends up

This is the last version. The Design tab starts with one service and one database and shows which number forces each extra box.

The whole system

Members load photos from a CDN backed by S3 and send requests to a gateway. The gateway reaches four services: swipe, deck, profile and chat. Swipe uses Cassandra for likes and matches and publishes to Kafka. Deck uses Redis and a geo search index. Profile uses PostgreSQL. A notifier reads Kafka and calls the phone push services, which are outside our system.
Pink is the swipe path, blue is building a deck and loading photos, orange is what happens after a match.

Four key ideas

  • One key per pair

    Both likes land in one partition, so one small read answers the question.

  • Write, then read

    The second writer always sees the first. The match id is computed, so two creators make one match.

  • Decks on demand

    Build the next hundred cards when a member is nearly out, not on a timer for everyone.

  • Blur the distance

    Precise distances can reveal a home. Round on the server.

Where to go

The tabs and the concepts

If you wantOpen
What the interviewer looks forApproach, By level
Targets and sumsScope, Numbers
Endpoints and tablesAPI and data
Matching, decks, distance, fairnessDeep dives
Practice against the clockMock
Quorums and copiesConsistency models, data replication
Safe retriesIdempotency
Live deliveryReal-time APIs, pub-sub
Photos at the edgeCDN, object storage

Summary

The whole topic in one minute.

The product is a loop: build a deck of people nearby, record an answer, look for the answer in the other direction, tell both people.

The design puts both likes of a pair in one partition, writes before it reads, and creates the match under an id that both sides compute alike. Decks are built when a member needs one, photos come from the edge, and everything after the match is an event.

  • A swipe is two ids and an answer. Volume is easy; order is hard.
  • Store both likes of a pair together, write before reading, and give every pair one home region.
  • A computed match id makes creating and announcing safe to repeat.
  • Build decks when they are needed. Doing it for everyone each 15 minutes costs about 32 times more.
  • Notifications can be late. The match row is the truth.

Sources