14 / 16

System Design Classics

The classic Staff interview designs: feeds, chat, payments, storage, real time.

0/23 studied
01Design: URL shortener

Give each long URL a short base62 key from a collision-free ID source, store key → URL in a sharded key-value store, serve redirects from cache, and log clicks asynchronously, off the redirect path.

Advanced◇ Diagram</> Code
02Design: distributed rate limiter

Enforce limits at the gateway with rules cached in memory and counters in a regional Redis updated by one atomic script; answer excess with 429 and Retry-After, and fail open if the limiter breaks.

Advanced◇ Diagram</> Code
03Design: news feed

Precompute each user's feed by pushing new post IDs into followers' cached lists, but pull posts from high-follower accounts at read time and merge; hydrate, rank, and page with cursors.

Staff+◇ Diagram</> Code
04Design: chat system

Clients keep a WebSocket to a gateway; the chat service gives each message a per-conversation sequence, stores it, then delivers to online recipients or via push; clients dedup and resync from their last-seen sequence.

Staff+◇ Diagram</> Code
05Design: notification system

Services emit events; the notification service dedups, checks preferences and caps, renders per channel, and queues sends by priority to channel workers that call APNs, FCM, email and SMS providers with retries.

Advanced◇ Diagram</> Code
06Design: search autocomplete (typeahead)

Precompute the top-K completions per prefix offline from query logs, serve them from an in-memory index behind browser and CDN caches, and answer each keystroke well under 100 ms; merge a trending layer for freshness.

Advanced◇ Diagram</> Code
07Design: web crawler

A URL frontier with one queue per host feeds fetch workers that obey robots.txt; new links pass a Bloom-filter seen-check, pages pass content dedup, and each host gets one request at a time.

Advanced◇ Diagram</> Code
08Design: distributed key-value store

Place keys on a consistent-hash ring, replicate each to N nodes, and wait for W write and R read acks; versions resolve conflicts, while gossip, hinted handoff and Merkle-tree repair ride out failures.

Staff+◇ Diagram</> Code
09Design: distributed cache

Partition keys across memory-only nodes by hash slot or consistent hashing, evict by LRU or LFU at a memory limit, replicate asynchronously for failover, and protect the database from hot keys and cold nodes.

Advanced◇ Diagram</> Code
10Design: video streaming platform

Upload the original once in resumable parts, transcode it in parallel chunks into a bitrate ladder of short segments, and serve them from a CDN; the player picks a quality per segment.

Advanced◇ Diagram</> Code
11Design: ride hailing (Uber, Lyft)

Drivers stream GPS every few seconds into an in-memory index of H3 cells; a request searches nearby cells, ranks drivers by road ETA, claims one atomically, and a trip state machine runs to payment.

Staff+◇ Diagram</> Code
12Design: proximity service (Yelp)

Index mostly static businesses by geohash cell; a search reads the user's cell plus its 8 neighbors from cache or read replicas, filters by exact distance, and widens the cell when results are few.

Advanced◇ Diagram</> Code
13Design: payment system

Record the payment intent, call the PSP with an idempotency key, and post the outcome as balanced double-entry ledger entries; webhooks and daily reconciliation against PSP reports catch whatever the synchronous path missed.

Staff+◇ Diagram</> Code
14Design: digital wallet

Move money between accounts on different shards as an idempotent debit-then-credit saga recorded in a double-entry ledger; the append-only log makes every balance reproducible, and reconciliation proves no money was created or lost.

Staff+◇ Diagram</> Code
15Design: ticket booking

Hold seats with one atomic conditional write that expires after ~10 minutes, charge with an idempotency key, then confirm only if the hold is still yours; a virtual waiting room meters the spike.

Advanced◇ Diagram</> Code
16Design: collaborative editor

One session server per document orders every edit, transforms or merges concurrent edits (OT or CRDT), appends them to an operation log and broadcasts them; cursors travel on a separate, ephemeral presence channel.

Staff+◇ Diagram</> Code
17Design: distributed job scheduler

Store each job's next run time; sharded schedulers claim due jobs and enqueue a run with a deterministic id; workers execute under heartbeated leases; delivery is at-least-once, so every job must be idempotent.

Advanced◇ Diagram</> Code
18Design: file sync (Dropbox)

Split files into hashed blocks, upload only blocks the server lacks, commit the file as a hash list with a version check, and tell other devices to pull changes since their cursor.

Advanced◇ Diagram</> Code
19Design: metrics and monitoring system

Buffer samples through an ingest pipeline into a compressed time-series store sharded by series, downsample old data for long ranges, cap label cardinality, and evaluate alert rules on recent data, independently of what they watch.

Staff+◇ Diagram</> Code
20Design: distributed message queue

Store each topic as partitioned append-only logs, replicate every partition from a leader to in-sync followers, acknowledge once they have the write, and let consumer groups pull by offset and commit their own position.

Staff+◇ Diagram</> Code
21Design: ad click aggregator

Log clicks to Kafka, drop duplicates by click id, count per ad per minute by event time with exactly-once output into an OLAP store, and reconcile against a batch recount of the raw log.

Staff+◇ Diagram</> Code
22Design: top-K and heavy hitters

Count events per item in time buckets, keep a size-K heap over the counts, and sum buckets for sliding windows; switch to a count-min sketch when exact per-item counters stop fitting in memory.

Advanced◇ Diagram</> Code
23Design: real-time leaderboard

Keep scores in a Redis sorted set: score updates and rank lookups are O(log N), the top 10 is one range read, and the set is a view rebuilt from the durable score store.

Advanced◇ Diagram</> Code