1. Functional requirements
- Create a profile: up to 6 photos or videos, 3 prompts with a text, voice, or video answer, basics, preferences, and dealbreakers, the hard filters on age, distance, gender, height, and more.
- Browse Discover, a stack of profiles that pass preferences and dealbreakers; like one photo or prompt with an optional comment, or skip with an X; free users get about 8 likes a day.
- Match on a mutual like, and both users get notified.
- See who liked you.
Below the line: chat after a match, and the photo and moderation pipeline.
2. Non-functional requirements
- Strong consistency on likes: when two users like each other, exactly one match is created, even if both likes land at the same moment [6.1]
- Low latency: Discover loads in under 300 ms [6.2]
- A profile you liked never comes back; one you skipped may return once the pool runs dry [6.3]
- Scale: 5M DAU; Discover ~5K/s at the evening burst, likes ~500/s; the read-heavy Discover feed, with the nightly batch, drives the design, and likes are write-light
3. Core entities
- User: account, basics, preferences, dealbreakers, location, plan; also the profile others see
- Content item: one photo, video, or prompt answer; what a like attaches to
- Like: from, to, content item, comment, kind like or rose; the row that makes a match
- Match: two users who liked each other; its own entity, as in Tinder: the like path creates it, both users list it, its id keys the push and the conversation
Likes You reads the Like from the recipient’s side [6.5]; conversations, messages, and entitlement balances arrive with their deep dives.
4. API routes
Identity comes from the JWT at the gateway, never from the body. Discover has no pagination; the app calls again when the stack runs out.
Create a profile
POST /profile
body: name, age, gender, height, lat, long, preferences, dealbreakers
returns: ok
Add or replace a photo, video, or prompt answer
PUT /profile/content
body: content_id, type photo | video | prompt, prompt_id, file or text, position
returns: content_id the upload goes to object storage [7.6]
Get the Discover stack
GET /discover?lat={}&long={}
returns: Profile[] preferences and dealbreakers, max distance included, are saved, so the server reads them; the call carries only what changes, the phone's location
Like a photo or prompt
POST /like/{userId} the profile liked
body: like_id, content_id, comment, kind like | rose like_id is the client’s idempotency key [6.1]
returns: match true | false, likes_remaining
Skip
POST /skip/{userId}
returns: ok the soft tier of the seen-set [6.3]
Likes You
GET /likes-you?cursor={}
returns: Like[], next_cursor each with the liker's profile card; free users see one and must act on it; subscribers the grid
No notification route: the liker learns of a match in the like response, the other user by push [7.5].
5. High-level design
The simplest system that serves the six routes: one client, one gateway, three services, three stores, push to phones. Three services because the traffic shapes differ: rare profile writes, read-heavy Discover, and likes, the one write that must be consistent.
One flow per requirement:
- Profile:
POST /profile→ gateway verifies the JWT → profile service → upsert in the user DB.PUT /profile/content→ the file to object storage, the row to the user DB; the client reads photos through the CDN. - Discover:
GET /discover?lat&long→ discover service → one query on the user DB: within distance, passing every dealbreaker, not me, not in my seen rows → Profile[].POST /skip/{B}→ a seen row, A, B, skip, in the user DB; a like writes the same row with kind like. - Like to match:
POST /like/{B}from A → like service → check A’s daily count → write the like row by the sorted pair → read B’s like on A → mutual: write the match row, return match true, push B. - Likes You:
GET /likes-you→ like service → read the like store by recipient, newest first → Like[], each hydrated from the like row and the liker’s profile.
Data model:
User id, name, age, gender, height, lat, long, preferences, dealbreakers, plan
ContentItem id, user_id, type photo | video | prompt, prompt_id, url, position, status
Like from_id, to_id, content_id, comment, kind, created_at partition key: sorted pair, clustered by from_id
Match id, user_a, user_b, created_at
Seen user_id, seen_id, kind like | skip, created_at what Discover excludes
Stores:
- User DB, Postgres: users, content items, matches, and the seen rows; profile writes are rare and reads are one row by id
- Like store, Cassandra, partitioned by the sorted pair: both directions of a pair sit on one node for the reverse-like read; 50M rows a day is light
- Object storage behind a CDN: photos are big, immutable, read by many
Weak spots, in the order the deep dives take them: the comment on a like is never checked against Hidden Words [6.4]; the like write and the reverse read are two steps, so simultaneous likes miss each other and the push can be lost or doubled [6.1]; the Discover query, geo plus a dozen filters on Postgres, runs on every call and will not make 300 ms at 5K/s [6.2]; “not in my seen rows” is a join on every Discover query against a table that grows forever, and a skip never returns [6.3]; the daily count has no home and no midnight [6.6]; Likes You scans the like store by recipient, with no entitlement check [6.5].
6. Deep dives
Order in the room, 60 minutes: 6.1 to 6.4 must, in that order; 6.5 and 6.6 if asked about Likes You or limits; the features in section 7 are one line each. Each deep dive opens with three spoken sentences, Problem, Pick, Cost; the rest is for when the interviewer digs.
| N | Feature | Mechanism | Fundamentals | Maps to |
|---|---|---|---|---|
| 6.1 | Like to match, idempotent, with an outbox | Atomic check-and-write on the pair key; Match row exactly once; match event in an outbox in the same write, a relay publishes it; a retried like is one match | atomicity, idempotency key, outbox, at-least-once | Tinder 6.1, like/match model |
| 6.2 | Discover feed | Geo plus dealbreaker filters on the search index, precomputed stack in Redis, refill when low, exhausted pool | geospatial index, CDC, cache lifecycle, TTL | Tinder 6.2, feed |
| 6.3 | Two-tier seen-set | Likes into a per-user Bloom filter, never return; skips into a TTL’d Redis set, may return when the pool runs dry; the phone keeps the last K | Bloom filter, TTL, client cache, eventual consistency | Tinder 6.3, feed |
| 6.4 | Like with a comment | A like is a row: from, to, content item, comment, kind; partitioned by the sorted pair, clustered by from; Hidden Words at write time; comment size cap | partition key, write path, validation | Tinder 6.1, like/match model |
| 6.5 | Likes You inbox | Fan-out on write into inbox:{to}, roses first; badge count; free users read the head, entitlement decides; remove on match, skip, unmatch; cursor pagination | fan-out on write, sorted set, entitlement check, pagination | Notification system, subscriptions |
| 6.6 | Daily like limit | Entitlement first; likes:{userId}:{localDay} INCR with EXPIRE to local midnight; compare to the plan’s limit; fail open or closed when Redis is down | atomic counter, TTL, time zones, fail open | Rate limiter, subscriptions |
6.1 Match once, tell once: outbox in the pair-key run, relay to the queue
Problem
- Two users who like each other in the same instant each read before the other writes, so no match is made.
- The push is a separate step, so a crash loses it and a retry doubles it.
Pick
- The like service writes the like row to the like store, then runs one Lua script on the sorted pair key in Redis: write my like, read theirs, create the match once, and append the match event to a stream in the same run.
- A small relay loop reads the stream, upserts the match row in Postgres, and publishes to Kafka under match-events, both keyed by the match id, which is the sorted pair.
Cost
- A relay and a stream to operate.
- At-least-once downstream, so the relay’s steps and every consumer are idempotent on the match id.
- The outbox is only as durable as Redis.
If it breaks
- A retried like is idempotent on its like id, finds the match already set, and adds nothing.
- A relay crash mid-way redoes its steps.
- Redis loses at most its last second, and the match and its event go together, never one without the other.
- An expired pair key is reloaded from the like store before the script runs, so an old like still matches.
Draw: inside Redis, the pair key with both likes and the match, the outbox stream beside it; the relay loop inside the like service reading the stream, arrows to the user DB and to a new queue, APNS/FCM behind the queue.
Details: ladder, flow, commands
Ladder
- Bad: the HLD: like row, reverse read, match row, APNS call, four steps in one service; simultaneous likes both read nothing, a crash after step three loses the push, a retry pushes twice.
- Good: the Lua run as in Tinder, then the match row and APNS inline. Simultaneous likes match, but the push is still a second step and APNS latency sits in the like’s response.
- Great, the pick: the event rides in the run, a relay publishes, consumers dedupe on the match id. Drawback: a relay and a stream to operate, at-least-once downstream.
Flow
- B likes A, A = 17, B = 42:
EVAL like.lua pair:17:42:HSET 42_like,HGET 17_like→ there, A liked B last week →HSETNX match 17:42→ 1 →XADD outbox {match: 17:42}→ match true. One shard, under a millisecond, nothing interleaves. A key past its TTL, 30 days as an assumption, reloads from the like store first, so an old like still matches. - Relay:
XREADGROUP outbox→ upsert match row17:42into the user DB, Postgres, where the HLD keeps matches → produce to Kafkamatch-events, key17:42, so chat and notifications read one topic in order per pair →XACK; a crash between steps redoes them, each idempotent on the match id. - Consumers: chat creates the conversation keyed by
17:42[7.4]; notifications push “You matched!” to A with17:42as the APNS collapse id, so a repeat replaces, never doubles [7.5]. - Retry: B’s phone times out and resends the same
like_id:like:{like_id}returns the first answer for a day; past that the run repeats,HSETNXreturns 0, match true, no second event.
6.2 Discover under 300 ms: dealbreakers inside the search query, a list of ids per user in Redis, a dry flag
Problem
- Every Discover call runs the HLD query on Postgres: a distance per row, a dozen dealbreaker checks and a join on the seen table, 5K a second at the evening burst, on the primary that takes the writes.
- In a small town or behind strict filters it comes back nearly empty, and the next pull-to-refresh runs it again for nothing.
Pick
- Postgres stays the system of record and serves point reads by id. Elasticsearch holds a read-optimized copy fed by CDC, seconds behind, where every dealbreaker and geo cell is a cached bitset. A feed can be seconds stale; likes and matches never come from it.
- The distance lookup (the geo index) and every dealbreaker go in one query as filter clauses, so only passing profiles come back.
- A list of about 30 candidate ids per user in Redis, served first. Each call takes the next 10; when fewer than 10 remain, one query on the Elasticsearch copy refills it with 30 more, after the call has answered.
- A nightly job builds the list for every user active this week, so the morning open is served from Redis.
- A dry pool lets skips back, never loosens a dealbreaker, and sets a dry flag so refresh does not query again.
Cost
- Double storage: a second copy of every profile in Elasticsearch, seconds behind Postgres.
- A few gigabytes of Redis for 10M lists of 30 ids.
- A list up to a day stale, so hydration drops anyone no longer published.
If it breaks
- The pool runs dry, a refill comes back under 10: Discover lets the oldest skips back first (skips sit in a per-user set with a 30-day TTL and stay hidden until then), never loosens a dealbreaker, and returns the few it has.
- The same call sets a dry flag, a per-user key with a ten-minute TTL, so pull-to-refresh runs no query. The end screen nudges a wider preference; widening deletes the list and the flag, so the next call runs live.
- The list is a day stale: hydration drops anyone no longer published.
- The list is missing: one live query, same as a refill.
Draw: Discover reading the Redis list first; the Elasticsearch copy with dealbreakers as filter clauses; the nightly job feeding Redis; the dry path as steps.
Details: the HLD query, why Elasticsearch, ladder, flow, commands
The HLD query, what Discover runs on Postgres before this deep dive:
SELECT id FROM users
WHERE lat BETWEEN :myLat - :d AND :myLat + :d
AND long BETWEEN :myLong - :d AND :myLong + :d -- bounding box
AND distance(lat, long, :myLat, :myLong) < :radius -- exact circle
AND age BETWEEN 25 AND 34 AND gender = 'woman'
AND smokes = 'no' AND drinks = 'sometimes' AND kids = 'want'
-- ... nine more dealbreakers
AND id NOT IN (SELECT seen_id FROM seen WHERE user_id = :me)
LIMIT 30;
No index serves this whole shape. A geo index fixes the distance part, then twelve columns are checked row by row, the seen clause is a join on a table that only grows, and all of it runs on the primary that takes the writes.
Why Elasticsearch beside Postgres
- Elasticsearch is a separate store with its own copy of every profile. Postgres stays the source of truth, and changes reach the copy through CDC seconds later.
- It is an inverted index: every filter value and every geo cell maps to a bitset of matching profiles. A twelve-filter query is twelve bitsets ANDed, and the bitsets are cached. That is exactly the shape of Discover.
- Its writes are slower and not transactional: every write rebuilds the document’s index entries and becomes searchable about a second later. So likes and matches never live there.
- Postgres is fast at a row by id, which is why hydration reads it, and slow at this one read: a search over millions of rows that combines distance with a dozen filters and a join.
- A geo index, also called a geospatial index, is the distance lookup inside a store: geohash cells in Elasticsearch, the PostGIS extension in Postgres.
Ladder
- Bad: the HLD query on every call: Postgres, a distance per row, twelve WHERE clauses, a join on seen.
- Good: Elasticsearch for distance only, dealbreakers filtered in the service afterwards. Drawback: rows fetched and thrown away, worst where the pool is already small.
- Good: Elasticsearch with lat/long as geohash cells and every dealbreaker a filter clause: cells narrow first, filters are cached bitsets, tens of ms. Drawback: a second copy, seconds behind, and a query per refill.
- Good: a precomputed list per user, off peak. Drawback: active users drain it; built for every registered user it is memory and queries for people who will not open the app.
- Great, the pick: the list first, a refill under 10, the job scoped to active users, the dry pool answered once and flagged.
Flow
- A, 17, opens Discover at 21:00 →
LPOP discover:17 10→ ten ids, hydrated by id, photos from the CDN; 8 left → after the answer, one query on the Elasticsearch copy, geo cells plus every dealbreaker, minus liked and skipped →RPUSH30,EXPIREa day. - B, 42, a small town, 12 dealbreakers: the refill returns 2; the oldest skips come back first, likes stay out, 6. Serve the 6,
SET discover:42:dry 1 EX 600, so pull-to-refresh does not query; the app shows the end screen with the nudge; B widens distance →DEL discover:42 discover:42:dry, the next call is live. - 03:00 job: users active this week, I’ll assume 10M, one query each, ~1K/s over 3 hours, every list fresh at the morning open; a preference or dealbreaker change or a big move →
DEL discover:{userId} discover:{userId}:dry, the next call is live. Load on the Elasticsearch copy: ~1 live query per user per day plus the build, hundreds a second, not 5K.
6.3 Two-tier seen-set: likes in a Bloom filter, skips in a timed Redis set
Problem. The HLD keeps likes and skips in one seen table, joined on every Discover query: a read per candidate against a table that only grows, and a skip never returns. A like is forever while a skip may return when the pool runs dry, so one grow-forever set is wrong on both counts.
Pick. Two tiers in Redis beside the stack. Likes go into a per-user Bloom filter, liked:{userId}, no deletes, so a liked profile never returns; skips into a sorted set, skipped:{userId}, scored by time, hidden while there, pruned after 30 days. A refill under 10 after both filters is a dry pool, so Discover lets the oldest skips back first, and the phone drops its last K from any stack.
Cost. Bloom false positives, about 1%, hide a few never-seen profiles for good; a lost filter means a point read per candidate on the like store until a batch rebuilds it; a skip over 30 days old can return before the pool is dry; and about 16 KB of Redis per active user, 80 GB over 5M. Rejected: one set of everything seen, which never lets a skip back.
Draw: the last K on the client; two accent ellipses on Redis, the Bloom fed by the like service, the skip set by POST /skip; the refill reads the index, then both tiers.
Ladder
- Bad: no seen-set, a point read per candidate on the pair partition: 200 reads per refill, 50K/s at the burst, the slowest one setting the latency, and a skip has no row. Kept as the fallback when a Bloom key is lost.
- Good: one Redis set per user of everything seen,
SISMEMBERper candidate. Exact; grows forever, 10K ids a year, and a skip never returns. - Great, the pick: RedisBloom for likes,
BF.RESERVEfor 5K at 1%, about 6 KB, constant space whatever the history, any zero bit means never liked; a sorted set for skips, score the time, so expiry is oneZREMRANGEBYSCOREand oldest first is oneZRANGE, about 700 ids over 30 days, ~10 KB. Drawback: a false positive is hidden for good; a full filter grows a sub-filter and the rate creeps up.
Flow
- A, 17, likes 42: the like row [6.1], then
BF.ADD liked:17 42; the phone adds 42 to its last K, say 100. - A skips 7:
ZADD skipped:17 now 7,EXPIRE 30drefreshed per skip, so an idle user costs nothing. discover:17under 10, refill [6.2]: the index returns 200 → prune skips over 30 days →BF.MEXISTSdrops the liked → the set drops the skipped → 60 ontodiscover:17→ the phone drops its last K from them.- Sparse town: 200 → 8, dry:
ZRANGE skipped:17 0 49, the oldest skips go back first; still under 10 → the dry-pool answer [6.2]. A failover loses seconds of writes: 42 is on the phone; a lostliked:17→ the point-read fallback until the rebuild.
21:00:00 like 42 row in 17:42, then BF.ADD liked:17 42 phone: last K += 42
21:00:30 skip 7 ZADD skipped:17 1762808430 7 · EXPIRE 30d
21:05:00 refill index 200 → prune → BF.MEXISTS drops 12 → set drops 128 → 60 onto discover:17
22:10:00 refill, dry index 200 → 8 → ZRANGE skipped:17 0 49, oldest first → 7 is back → 58
6.4 Like with a comment: a pair-keyed row, checked before the write
Problem. A Hinge like is not a bit: it points at one photo or prompt and carries a comment. The HLD writes that comment unchecked, so a word on B’s Hidden Words list still reaches B’s inbox.
Pick. A like is a row, from_id, to_id, content_id, comment, kind, hidden, created_at, in Cassandra, partitioned by the sorted pair and clustered by from_id, so both directions sit in one partition and the reverse like is one row on the same node. Before the write, the like service checks the comment cap, that the item is B’s and published, and B’s Hidden Words. A hit is still written, flagged hidden: no inbox entry, no push.
Cost. Two extra cached reads per like, the item and B’s word list; a few hundred bytes per row instead of one bit; and the pair partition cannot answer “who liked me”, so Likes You is fed at write time [6.5]. Rejected: a bit-sized like with the comment in its own table, two writes that can land apart.
Draw: a check step in the like service, in accent; Redis gains hidden_words:{B}; the like store row grows from a bit to the full row.
Ladder
- Bad: a bit per pair as in Tinder, the comment in its own table: two writes, no transaction, a like without its comment, no record of which photo.
- Good: one row partitioned by
from_idalone: the reverse like sits on another node, two steps on two nodes, and simultaneous likes miss each other. - Great, the pick: one row, partition key the sorted pair, clustering key
from_id, at most two rows per partition, so no hot partitions; check before the write. Drawback: two cache reads per like, and a miss on the word list must fail safe: like written, comment held.
Flow
- A, id 17, likes B’s prompt, B is 42, comment “The second one is the lie, right?” → like service → counter [6.6] → checks: 34 chars, under the cap, I’ll assume about 300; p3 is B’s and published;
SMEMBERS hidden_words:42, no hit. - Write the row into partition 17:42 under from_id 17; read from_id 42 in the same partition, nil, no match; entry onto
inbox:42[6.5]; respondmatch false, likes_remaining 5. - C, id 88, likes 42 with a word on 42’s list: row written hidden true, no inbox entry, no push.
partition 17:42 from 17 to 42 p3 "The second one is the lie, right?" like hidden false 21:00:00
partition 17:42 from 42 to 17 ph1 "" like hidden false 21:03:10 reverse row found: match [6.1]
partition 42:88 from 88 to 42 p1 "..." like hidden true 21:05:00 Hidden Words hit: no inbox, no push
6.5 Likes You: fan-out on write into a sorted set, head or grid by plan
Problem. The HLD reads the like store by recipient on every open, a scan across partitions keyed by pair, with no entitlement check, so a free user pages the whole grid. Nothing removes an entry on match, skip, unmatch, or block.
Pick. Fan-out on write: a like, not hidden and not a match, is one ZADD onto inbox:{B}, score the time in ms plus 1e13 for a rose, so roses first then newest, and one INCR on badge:{B}. On read the like service checks entitlement:{A}: free users get the head only and must act on it, subscribers page the grid with the last score as the cursor. Match, skip, unmatch, and block ZREM the entry, and a second like-store table, likes_by_to, written on the same flush, rebuilds a lost set.
Cost. A Redis write and a second Cassandra row per like, cheap because likes are capped; a set per user in memory, capped at 1,000 with the tail in the table; four removal paths to keep in step. Rejected: fan-out on read from the like store on every open; opens outnumber likes, and the pair partition cannot answer who liked me.
Draw: ZADD into inbox:{to} with the score rule; the entitlement cache before the read; ZREM from skip; likes_by_to behind Redis, a rebuild arrow; the new like push.
Ladder
- Bad: fan-out on read against the pair partitions: who liked me is a scan or a secondary index on every open.
- Good: fan-out on read against
likes_by_to: one partition read per open, roses first by the clustering key. Drawback: a disk read per open, removals as tombstones. - Great, the pick: fan-out on write into Redis, the table behind it for rebuild and the tail; it wins because opens outnumber likes and a like has one recipient: one entry, not a broadcast as in a social feed. Drawback: a second write per like, a cache four paths must keep in step.
Flow
- B, 42, roses A, 17 → the Hidden Words check [6.4], not hidden → the pair-key run [6.1], no match →
ZADD inbox:17 11793826000000 42,INCR badge:17→ 3 → notifications push with the badge [7.5]. A retry repeats the ZADD, same member, same score: one entry. - A, free, opens Likes You:
entitlement:17→SET badge:17 0,ZREVRANGE inbox:17 0 0→ 42, hydrated from the like row and the profile, no cursor. Like back → match [6.1] →ZREM inbox:17 42, nothing ontoinbox:42; skip → the discover service adds the skip [6.3], and the ZREM. - C, 88, Hinge+, 300 waiting:
ZREVRANGEBYSCORE inbox:88 +inf -inf LIMIT 0 20,next_cursorthe 20th score; a like arriving mid-scroll lands above the cursor, so no page shifts. - Node lost:
EXISTS inbox:17→ 0 → readlikes_by_topartition 17, state pending,ZADDeach with the same score.
21:00:00 ZADD inbox:17 11793826000000 42 rose from B, 1e13 + ms badge 3
21:02:15 ZADD inbox:17 1793826135000 88 like from C, ms badge 4 head stays 42
6.6 Daily like limit: entitlement first, then a Redis counter per local day
Problem. The HLD “checks the daily count” with no store named: a count on the like store per like, a day that resets at UTC midnight, 9 am in Tokyo, subscribers counted though they have no limit, and no answer when the counter is down.
Pick. Entitlement first, so subscribers skip the counter. A free like runs INCR likes:{userId}:{localDay}, the day in the user’s own time zone, EXPIRE to that midnight on the first like, and the ninth is a 429. Redis down: fail open under a loose local count.
Cost. One Redis command per free like, ~1 ms; a time zone on the user row; and a few extra free likes while Redis is down, which I take over a product that cannot like. Rejected: fail closed, the product down for a rule worth a few likes.
Draw: entitlement cache before Redis; local day in the counter key; a local count in the like service; a time zone on the user row.
Ladder
- Bad: count on the phone. Free; a second device or a patched client starts at 8 again.
- Good: a
likes_todaycolumn in Postgres,UPDATE ... WHERE likes_today < 8. Atomic, durable; a row write per like on a DB sized for rare writes, plus a reset job per time zone. - Great, the pick: the rate limiter’s fixed window in Redis: one INCR, atomic since Redis runs one command at a time, reset free since the day is in the key. Not durable: a failover loses seconds of counts.
Flow
POST /like/{B}from A → like service, not the plan-blind gateway limiter → plan from the entitlement cache [7.1], or the user row on a miss. Subscriber: straight to the write,likes_remainingnull.- Free:
localDayis today in A’s time zone from the user row, never from the request, so a clock change mints no new key.INCR likes:{A}:{localDay}→ n; n == 1 →EXPIREseconds to A’s local midnight; tomorrow is a new key, EXPIRE is only cleanup. - n > 8 → 429,
likes_remaining0, nothing written; else the atomic write [6.1], andlikes_remaining8 - n. A failed write or a duplicate like [6.1] →DECR, so a retry counts once. - Redis timeout or open breaker → fail open: a per-user count in like service memory, loose across instances; alert on time in fail-open.
Free user 17, time zone New York, limit 8:
09:00:00 likes:17:2026-11-09 INCR → 1, EXPIRE 54000 like, 7 left
…
20:30:10 …:2026-11-09 INCR → 8 like, 0 left
20:31:02 …:2026-11-09 from a tablet INCR → 9 429, 0 left
21:10:00 Redis timeout fail open, local count like, loose; alert
00:00:00 …:2026-11-09 expired
00:05:00 likes:17:2026-11-10 INCR → 1, EXPIRE 86100 like, 7 left
7. Features
Each one is a spoken line in the room unless the interviewer asks; then it opens like a deep dive, Problem, Pick, Cost.
| N | Feature | Mechanism | Fundamentals | Maps to |
|---|---|---|---|---|
| 7.1 | Roses and boosts ledger | Append-only debits and credits with an idempotency key; store receipt validated server-side; store webhooks retried, idempotent by transaction id; entitlement cache with a short TTL | ledger, idempotency, webhooks, cache | Subscriptions and consumables |
| 7.2 | Most Compatible | Offline daily batch: retrieval by filters and geo, ranking by a model over mutual preferences and behavior, a stable-matching pass per cohort; cached per user before the morning open | batch pipeline, retrieval then ranking, feature store, cache | Recommendation system |
| 7.3 | Standouts | Same pipeline over content items; daily refresh; a rose required to like, so the entitlement check sits in the like path | batch pipeline, cache | Recommendation system |
| 7.4 | Chat after a match | Conversation keyed by match id; messages partitioned by conversation plus time bucket; persistent connection, push when offline; unread counts; Your Turn a flag; unmatch hides both sides | partitioning, websocket, unread counters | Chat |
| 7.5 | Notifications | Outbox events onto a queue; a notification service applies preferences, batches like notifications, respects quiet hours; APNS and FCM; at-least-once, event id as the idempotency key | queue, fan-out, idempotent consumer, batching | Notification system, Tinder 6.4 |
| 7.6 | Photo and prompt pipeline | Presigned upload to object storage; async workers resize and run nudity, face, and selfie-verification checks; publish gate; CDN in front | object storage, async workers, CDN, moderation gate | Photo pipeline |
| 7.7 | Trust and safety | Block is a filter on both users’ feeds, inboxes, and chat; report to a review queue; Hidden Words at like-write time; abuse rate limits and shadow-limiting | filters, queues, rate limits | Trust and safety |
7.1 Roses and boosts: an append-only ledger, idempotent by key
Problem. The HLD has no ledger: a rose is only kind on the like row, nothing debits it, a purchase has nowhere to land, and a retried like or webhook counts twice.
Pick. Entitlement gets a store: an append-only ledger in Postgres, a row per credit or debit with a unique idempotency key, the balance a cached sum with a short TTL. A rose like debits inside the like request, and a failed like writes a refund row. Credits come from a store receipt validated server-side plus retried store webhooks, both keyed by the store transaction id.
Cost. A Postgres transaction per rose and purchase, light because roses are rare; a balance up to a minute stale, fine because the ledger, not the cache, is the gate; two store integrations. Rejected: a roses column decremented in place, no history, a retry decrements twice.
Draw: entitlement service, ledger, entitlement cache, the store with receipts and webhooks in.
Ladder
- Bad: a
rosesinteger on the User row, decremented in place: no history, a retry debits twice. - Good: add
WHERE roses > 0and a purchases table: atomic, but the webhook handler has no key, a retry credits twice. - Great, the pick: append-only rows,
idem_keyunique,INSERT ... ON CONFLICT DO NOTHING, so a retry is a no-op. Drawbacks: a monthly snapshot row keeps the sum short; a debit whose like never landed needs a refund sweeper.
Flow
- A, 17, buys a 3-rose pack; the app posts the signed transaction to
POST /purchase→ entitlement service → verify with the store’s API →INSERT (17, rose, +3, purchase, appstore:9001),DEL entitlement:17; the webhook for 9001, retried, hits the same key: no-op. - A roses B, 42:
POST /like/42 kind rose→ like service →entitlement:17→ roses 3 → entitlement service, one transaction:INSERT (17, rose, -1, rose, rose:17:42)if the sum covers it, else 402 → like row [6.4, 6.1] → inbox top [6.5]. - A timeout is not a failure: the retry finds the debit and writes the like; B’s account gone is a hard fail, refund row
refund:17:42. - A boost is a debit whose
refholds the window, I’ll assume 1 or 24 hours; subscriptions setplanby the same webhooks.
user asset delta kind idem_key balance
17 rose +3 purchase appstore:9001 3
17 rose -1 rose rose:17:42 2
17 rose -1 rose rose:17:88 1 88 gone: hard fail
17 rose +1 refund refund:17:88 2
7.2 Most Compatible: a nightly batch, retrieve, rank, stable-match, one pick cached per user
Problem. One mutual pick a day for the 5M daily actives, candidates from the 10M active this week. Scored on open it is one-sided and a model call per open, so it is a batch, the heaviest job, due before the morning open.
Pick. A nightly batch in the Discover refill window [6.2], over users active this week. Retrieve per user with Discover’s geo and dealbreaker query on the search index; rank by a model over mutual preferences and behavior from a feature store; a stable-matching pass per cohort so a pick is mutual; most_compatible:{userId} to Redis before 06:00 local.
Cost. I’ll assume a few hundred candidates per user, a billion scores a night, a worker fleet for three hours; a cohort past 05:00 keeps yesterday’s pick and alerts; a new user has no behavior: preferences only.
Draw: three batch boxes between the search index, a feature store, and Redis.
7.3 Standouts: the Most Compatible batch over content items, a rose to like
Problem. A daily set of prompts and photos from people likely to be compatible, liked only with a rose; the HLD has no batch output for content items, and the like path cannot tell a Standout from a free like.
Pick. A second output of the Most Compatible batch [7.2]: after ranking, each top candidate’s best prompt or photo, I’ll assume 10 per user, to standouts:{userId} in Redis, dated. The like service checks the content id against that set, requires kind rose, and runs the rose debit first [7.1].
Cost. A second write per user in the batch, one Redis read per like, and a set only as fresh as the batch: a Standout who deactivates at noon stays listed until tomorrow unless the read drops it.
Draw: the batch’s second output into Redis, the rose gate on the like path.
7.4 Chat: one conversation per match, messages by conversation and month, socket or push
Problem. The HLD ends at “You matched!”: no conversation, nowhere for messages, no path to an open phone, nothing on whose turn it is.
Pick. The chat service consumes match-events and creates a Conversation keyed by the match id; messages in Cassandra partitioned by conversation id plus a month bucket, so one conversation is one partition and a long one stays bounded. Delivery: the other user’s WebSocket when the connection gateway holds one, else a push [7.5]. Redis counts unread:{userId}:{matchId} and your_turn:{userId}; Your Turn is a flag on the Conversation, flipped per message; the like service reads the count at like time, I’ll assume about 8 unanswered pauses new likes. Unmatch sets hidden on the Conversation, both sides filter it out.
Cost. A stateful connection gateway to run, and ordering only within one conversation.
Draw: queue → chat service → message store; connection gateway, Redis, APNS/FCM below.
7.5 Notifications: one consumer, prefs, digests, the push only a hint
Problem. Five event types from three services; APNS inline is five push paths, no preferences, no quiet hours, a buzz per like.
Pick. Every event rides the outbox [6.1] onto the Kafka queue; one notification service consumes, checks prefs:{userId}, opt-outs and quiet hours, folds likes into digest:{userId}, one push per window, and sends through APNS or FCM. At-least-once: the event id as idempotency key, SET NX sent:{eventId}, and a collapse id, so a retry replaces, never doubles.
Cost. A queue and a service to run, and a batched like that arrives late by design; the push is only a hint: the match row, inbox, and conversation are the truth, reconciled on open.
Draw: the relay and queue [6.1], the notification service, Redis, APNS/FCM back to the client.
7.6 Photos: presigned upload, async checks, publish gate
Problem. The file streams through the profile service and the row is live as it lands: one size, no nudity, face, or selfie check; a bad photo reaches Discover before anyone looks. Pick. The client asks the profile service for a presigned URL and PUTs straight to object storage, so bytes never pass through the service. The object-created event starts async workers: resize to the app’s sizes, nudity and face checks, for verification a match against the live selfie. The ContentItem row goes pending, then published or rejected; only published items are indexed and served, through the CDN. Cost. Minutes from upload to visible, a worker fleet, and a review queue for the checks that are not sure.
Draw: presigned PUT to object storage, event to workers, gate on the row, CDN.
7.7 Trust and safety: read-time block, review queue, shadow-limit
Problem. The HLD has no block, no report, no eye on abuse: a blocked user still shows in Discover, inbox, and chat; a thousand likes an hour looks normal.
Pick. A block is a pair row and a member of blocked:{userId} on both sides in Redis, read at Discover refill, inbox open, and chat list; both inboxes drop the entry [6.5]. A report queues with a snapshot: row, comment, last messages. Repeated reports, a like-rate spike, or Hidden Words hits [6.4] set shadow:{userId}: likes write the row, no inbox, no push, the account never learns. Abuse limits: gateway per client, like service per account.
Cost. A reviewer team and a queue, and a filter read on every Discover refill and inbox open.
Draw: blocked set and shadow flag in Redis, read by Discover and Like; review queue; reviewers and signals set the flag.
Final design
One picture, grown in this order: the HLD; then Redis gains its keys as the deep dives land, pair:{a}:{b} with the outbox stream and the relay behind it [6.1], likes:{user}:{localDay} [6.6], liked:{user} and skipped:{user} [6.3], inbox:{user} and badge:{user} [6.5], entitlement:{user} with the ledger in Postgres [7.1], most_compatible:{user} and standouts:{user} fed by the nightly batch [7.2 and 7.3]; then the queue, with the chat service and the notification service consuming [7.4 and 7.5]; the upload workers and the CDN beside object storage [7.6]; the safety service with its review queue [7.7].
Two stores, two mechanisms, say both: a geospatial index on profiles in the search database, for who is near and passes the dealbreakers; a partition key on likes in Cassandra, the sorted pair, so both directions of a pair sit on one node.
Trade-offs, the three to say:
- Redis in front of Cassandra for the like path [6.1]: one atomic step at memory speed with the outbox inside it, at the cost of a cluster to run and an unflushed window to lose.
- Precomputed per-user lists over querying at request time [6.2, 6.5, 7.2]: Discover, the inbox, and the daily pick each come from one key, at the cost of memory per active user and staleness bounded by a TTL or the nightly run.
- Fail open on the daily limit and best-effort push [6.6 and 7.5]: the product keeps working when Redis or APNS blinks, at the cost of a few extra likes and a late notification; the rows are the truth, the push and the counter are hints.