Skip to content
System design · Chapter 21 of 21 Appendix C: Interview problems

Appendix C: Interview problems

Five classic problems from system design interviews, each played through the way you would solve it at the whiteboard in 45 minutes. The difference from the usual model answers: behind almost every building block there is a day in this course on which you built it, measured it and broke it. You may say so in the interview. “I measured that …” beats “people say that …”.

The process in four steps

Step Time What you do
1. Requirements 5 min Clarifying questions: what exactly, for whom, how much, what not? Write down goals and non-goals
2. Estimation 5 min Requests per second (average and peak), storage, read-to-write ratio
3. Design 15 min The simplest architecture that handles the numbers. Data model, API, building blocks
4. Deep dive 20 min Bottlenecks, failures, trade-offs. This is where the interview is decided

The calculations are given as awk so you can recompute them on s1. In the interview you calculate in your head and round boldly: a day has roughly 100,000 seconds.

C.1 A URL shortener

Problem: “Design a service like bit.ly.” The problem of this course, now in 45 minutes and with bigger numbers.

Clarifying questions and assumptions:

  • 100 million new links per month, 100 redirects per link, so a read-to-write ratio of 100 to 1.
  • Links stay for 10 years. Custom codes: no. Click statistics: yes, may lag a few seconds behind.
  • Redirects fast (p95 under 50 ms), creating may be slower.

Estimation:

# on s1
awk 'BEGIN { neu = 100e6 / 30
  printf "Anlegen: %.0f/s im Mittel\n", neu / 86400
  printf "Lesen:   %.0f/s im Mittel, %.0f/s Spitze\n", 100 * neu / 86400, 300 * neu / 86400
  printf "Speicher 10 Jahre: %.1f TB\n", neu * 365 * 10 * 376 / 1e12 }'

Expected:

Anlegen: 39/s im Mittel
Lesen:   3858/s im Mittel, 11574/s Spitze
Speicher 10 Jahre: 4.6 TB

376 bytes per link is the value you measured for new links on Day 15.

Design:

Client → Load Balancer (quota, load shedding)
       → app instances (stateless, N+1)
          ├─ GET /{code}: cache → replica → primary, click asynchronously into the queue
          └─ POST /api/links: Idempotency-Key, dedupe, INSERT ... ON CONFLICT
       → cache (cache-aside, TTL with jitter)
       → database primary + replicas, later sharded by code
queue (stream, 24 h) → counter (batch, exactly once) → statistics table

Deep dive the interviewer wants to hear:

  • Codes: random, 7 characters out of 57, so roughly 2 trillion. With 12 billion links in 10 years the space is less than one percent full, collisions stay rare and are handled with ON CONFLICT and a new attempt (Day 9). Alternative: a counter per shard with Base57 encoding, but then codes are guessable.
  • Reads: 11,574 per second at peak is, at 1500 per core (Day 15), a good 8 cores for the app. With a skewed distribution, the cache absorbs over 95% (Day 5); the database only sees the rest.
  • Storage: 4.6 TB fits on one machine, but not comfortably with index and replica. Shard by code, with fixed slots instead of modulo, so a new shard moves only a third (Day 9).
  • Failures: the table from your design document (Day 15). Most important sentence: redirects survive a database outage for all links in the cache.
  • Clicks: never synchronously into the database; on Day 10 that cost p95 110 instead of 16 ms.

C.2 A rate limiter

Problem: “Design a rate limiter for a public API with 10 million customers.”

Clarifying questions and assumptions:

  • Limits per API key, several tiers (100/s, 1000/s). Shared across all gateway instances, not per instance.
  • One billion requests per day. A few milliseconds of added latency are allowed. A few requests too many during network problems are better than locking out legitimate customers.

Estimation:

# on s1
awk 'BEGIN { printf "Prüfungen: %.0f/s Spitze\n", 3 * 1e9 / 86400
  printf "Zähler:    %.0f MB bei 2 Fenstern zu je 100 Byte\n", 10e6 * 2 * 100 / 1e6 }'

Expected:

Prüfungen: 34722/s Spitze
Zähler:    2000 MB bei 2 Fenstern zu je 100 Byte

Design:

Client → gateway instances → counter store (Valkey, distributed by key)
             │  too many: 429 + Retry-After
             └→ backend

Deep dive:

  • Algorithm: A fixed window is simple but lets twice the limit through at the window boundary. A sliding window or token bucket smooths this out. HAProxy estimates a sliding window from two periods with gpc_rate. On Day 12 you saw what that means for bursts: 1000 requests every 10 s got through with a 5-s window, every 6 s only 271.
  • What counts: only admitted requests. Counting rejected ones locks a customer out permanently as long as they keep knocking. On Day 12 that left the noisy customer with 200 instead of 3999 requests in 20 s.
  • Counting distributed: a counter per gateway instance is fast but allows N times the limit. Centrally in Valkey with INCR + EXPIRE (or a script) is exact but costs a network round trip. Middle ground: count locally, sync every 100 ms.
  • Counter store failure: fail open (let requests through) and alert, do not block everything. Behind it, load shedding still protects the backend (Day 12).
  • What the client gets: 429 with Retry-After, and the client retries with backoff and jitter (Day 11). Without jitter, all rejected clients come back in the same second.

C.3 A notification service

Problem: “Design a service that sends push notifications, emails and SMS, triggered by other services.”

Clarifying questions and assumptions:

  • 50 million users, 5 notifications per day on average. Messages may take seconds to minutes, but must not be duplicated and not lost.
  • External providers (push services, email, SMS) are slow and sometimes fail.
  • 30 days of history for support; users can unsubscribe from channels.

Estimation:

# on s1
awk 'BEGIN { n = 50e6 * 5
  printf "Nachrichten: %.0f/s im Mittel, %.0f/s Spitze\n", n / 86400, 3 * n / 86400
  printf "Verlauf 30 Tage: %.0f GB bei 500 Byte\n", n * 30 * 500 / 1e9 }'

Expected:

Nachrichten: 2894/s im Mittel, 8681/s Spitze
Verlauf 30 Tage: 3750 GB bei 500 Byte

Design:

services → API (Idempotency-Key required) → stream “notifications”
  → dispatcher (preferences, unsubscribes, templates)
     → stream per channel: push | mail | sms
        → sender per channel (batch, own quota at the provider, circuit breaker)
  → history (database, partitioned by day, 30 days)

Deep dive:

  • No duplicates: The triggering service sends an idempotency key, and the API stores it (Day 11). The stream deduplicates via Nats-Msg-Id within its window. The sender records sent IDs in the same commit in which it acknowledges, like zaehler with klicks_verarbeitet.
  • Nothing lost: JetStream with a durable consumer and explicit acknowledgment. A sender that crashes before acknowledging gets the message again. That is why sending must be idempotent, or the provider must accept its own idempotency key.
  • Slow providers: a separate stream per channel, so an SMS outage does not hold up push notifications. Per provider a timeout, a circuit breaker and a quota according to its contract (Day 12, 13). Retry with backoff, after N attempts into a dead-letter queue.
  • Limits: by time, not by count. A stream with max-msgs loses data silently as soon as a sender stalls (Day 10, Appendix B).
  • Storage: 3.75 TB of history does not belong in the table the dispatcher reads for every message. Partition by day; old partitions are dropped instead of deleting individual rows.

C.4 A news feed

Problem: “Design the timeline of a social network: users follow others and see their posts, newest first.”

Clarifying questions and assumptions:

  • 200 million daily active users, 2 posts per user per day, 200 followers on average, some accounts with many millions.
  • Each user opens the timeline 10 times a day. A post may take a few seconds to appear for everyone.

Estimation:

# on s1
awk 'BEGIN { du = 200e6; posts = du * 2; f = 200
  printf "Beiträge:          %.0f/s Spitze\n", 3 * posts / 86400
  printf "Fan-out Schreiben: %.0f Einträge/s Spitze\n", 3 * posts * f / 86400
  printf "Timeline-Abrufe:   %.0f/s Spitze\n", 3 * du * 10 / 86400
  printf "Timeline-Cache:    %.0f GB (800 IDs zu 8 Byte je Nutzer)\n", du * 800 * 8 / 1e9 }'

Expected:

Beiträge:          13889/s Spitze
Fan-out Schreiben: 2777778 Einträge/s Spitze
Timeline-Abrufe:   69444/s Spitze
Timeline-Cache:    1280 GB (800 IDs zu 8 Byte je Nutzer)

Design:

POST /post    → posts (database, sharded by author)
              → stream → fan-out worker → timeline cache per follower (list of newest IDs)
GET /timeline → read timeline cache
              + merge in posts of large accounts at read time
              → fetch posts for the IDs from the cache

Deep dive:

  • Push or pull: Distributing on write (fan-out on write) makes reads cheap, but costs 2.8 million writes per second and explodes for accounts with millions of followers. Gathering on read (fan-out on read) is cheap on write, but expensive at 69,000 fetches per second. The usual answer is hybrid: distribute for normal accounts, merge in at read time for the few large ones.
  • Asynchronous: The fan-out runs through a queue; the author does not wait for it. The “a few seconds” from the requirements is exactly the lag you measured for zaehler on Day 10.
  • Cache: Spread 1.3 TB of timeline cache across several nodes, by user. Keep only active users in it, rebuild inactive ones on first fetch, like the cold start from Day 6, with singleflight against concurrent rebuilds.
  • Consistency: A user must see their own post immediately (read your writes); others may see it later. That is the problem from Day 8 with fresh links on the replica, solved the same way: ask the primary for your own view, or merge your own post in directly.

C.5 A distributed key-value store

Problem: “Design a key-value store for 10 TB of data that survives machine failures.”

Clarifying questions and assumptions:

  • 10 TB of payload data, values up to 1 MB, 100,000 reads per second, writes a tenth of that.
  • Is availability more important than immediate consistency? That is the clarifying question of this problem. Assumption here: configurable per request.
  • Machines with 2 TB of usable storage.

Estimation:

# on s1
awk 'BEGIN { d = 10e12; r = 3
  printf "Daten mit 3 Kopien: %.0f TB\n", d * r / 1e12
  printf "Knoten bei 2 TB:    %.0f\n", d * r / 2e12
  printf "Lesen je Knoten:    %.0f/s (jede Kopie liest mit)\n", 100000 * 3 / 15 }'

Expected:

Daten mit 3 Kopien: 30 TB
Knoten bei 2 TB:    15
Lesen je Knoten:    20000/s (jede Kopie liest mit)

Design:

Client → any node (coordinator)
       → hash(key) on a ring with virtual nodes → the next 3 nodes hold copies
       → write: to all 3, done after W acknowledgments
       → read: from R nodes, newest version wins

Deep dive:

  • Distribution: consistent hashing with virtual nodes. A new node takes over only part of the keys, not two thirds as with modulo. You measured exactly this difference on Day 9: 66.7% versus 32.8% with fixed slots.
  • Quorum: With N = 3 copies, R + W > N means reads and writes overlap in at least one node. W = 2, R = 2 is strongly consistent and survives one failure. W = 1, R = 1 is fast and always available, but reads stale data. That is CAP from Day 14, just configurable per request.
  • Conflicts: Without a single primary, two nodes can accept different values at the same time, like the two primaries on Day 14. Solution: versions (vector clocks or timestamps with “last write wins”) and reconciliation on read (read repair) and in the background.
  • Detecting failures: gossip and heartbeats instead of a central health check. A node that does not respond is not necessarily dead. Hence short timeouts and hinted handoff: another node accepts writes on its behalf and hands them over later.
  • When not to build it yourself: almost always. In the interview, the problem shows whether you know the trade-offs. In operations you take a proven system and know its settings for R and W.

What goes over well in every interview

  • Numbers first. If you estimate before drawing, you design for the right size. If you draw first, you end up defending a box you do not need.
  • The simplest solution that handles the numbers, and then say when it stops being enough. A server with a replica is not an oversight for 39 writes per second, it is the right call.
  • Every trade-off with its price. Asynchronous means stale. Cache means invalidation. Replica means lag. Sharding means moving data. Synchronous replication means hanging without a replica.
  • Play through failures before the interviewer asks: “What happens if the cache goes down?” You tried it on Day 6.
  • Measure instead of claim. For 16 days you backed every decision with k6. Say what you measured, and add that it was your lab: numbers change with the hardware, the order of magnitude and the direction do not.

Contents

More