Lesson 38 of 38Case studies
Wrap-Up: System Design
Tie the whole System Design course together: one marketplace designed end to end with the building blocks from every unit, a mixed review, and where to go next.
You started this course with boxes, arrows, and the idea that every design is a set of trade-offs. Since then you have turned users into QPS, put caches, queues, and replicas in front of databases, looked inside storage engines, kept data correct across services, learned to run all of it in production, and designed sixteen real systems. On the job, and in an interview, those pieces never arrive one at a time. This lesson lines the units up once more and then uses them together on one design.
The path you took
Unit 1
Building blocks
Requirements, estimation, DNS, CDNs, load balancers, caches, databases, replication, consistency, queues, APIs, rate limits, and blob storage gave you the parts every design is made from.
Unit 2
Data internals
Pages, the write-ahead log, B-trees, LSM trees, and ID schemes showed why a database is good at some workloads, which shapes every data model that follows.
Unit 3
Distributed systems
Consensus, sagas and the outbox, and Kafka-style logs explained how many machines agree and stay correct when any of them can fail.
Unit 4
Running in production
SLOs, timeouts and retries, multi-region recovery, and search turned a design that works on a whiteboard into one that survives real traffic.
Unit 5
Case studies
Sixteen full designs, from a URL shortener to a Ticketmaster on-sale, practiced combining the blocks under time pressure, the way interviews and design reviews really ask.
How it fits together
The prompt: "Design a second-hand marketplace. Sellers list items with photos, buyers search, message sellers, and pay in the app. We expect five million daily users in Europe." Here is how the course shows up, in the order you would really work.
Requirements first. Following What Is System Design, you ask before you draw. Functional: create listings with photos, search, view a listing, chat, check out. Non-functional, written as numbers: listing pages at p99 under 300 ms, checkout never charges twice, search results may be a few seconds stale, and 99.9% availability for browsing. You note the two hard parts out loud: search freshness and correct payments.
Rough numbers. Back-of-the-Envelope Estimation turns five million users who each view about 20 pages a day into roughly 1,200 reads a second on average and a few thousand at peak. New listings are far rarer, perhaps 50 a second. That is a read-heavy system, so caching and replicas will matter more than raw write throughput. Each listing has about five photos of a few hundred kilobytes each, so photos dominate storage and bandwidth by orders of magnitude.
The API. From API Design, plain REST for the app: POST /listings, GET /listings/{id}, GET /search?q=, and POST /orders with an idempotency key header. Search uses cursor pagination, as in Design a News Feed. Chat needs a long-lived connection, so it gets WebSockets through a gateway, exactly like Design a Chat App.
The edge. DNS, CDNs, and Client Caching puts photos and static assets on a CDN with versioned URLs, so most bytes never reach your servers. Load Balancers spreads API traffic across stateless app servers, with health checks and draining so deploys drop nothing. Rate Limiting sits at the gateway with a token bucket per user in Redis, which protects search and stops scrapers.
Photos. Storage and Blobs says metadata in the database, bytes in object storage. The app asks for a presigned URL, uploads straight to the bucket, and an event triggers a resize job. The listing row only stores the object keys.
The data. Databases makes Postgres the default for listings, users, and orders, because orders need transactions. IDs come from Generating Unique IDs: UUIDv7 keeps inserts close together in the B-tree index you studied in How Databases Store Data, and a short public slug hides the internal key. You start with one primary and read replicas from Replication and Sharding, and plan the shard key now (seller ID for listings) even though one primary handles 50 writes a second easily.
Caching reads. Caching adds cache-aside in Redis for hot listing pages with a TTL and delete on update. You guard against a stampede on a viral listing with request coalescing, and you know from Design a Distributed Cache how that cluster partitions keys and what a failover can lose. Consistency and CAP sets the honest promise: a buyer may see a price that is a few seconds old on the listing page, but checkout always reads the primary.
Search. LIKE will not survive, so Search and Inverted Indexes gives you an OpenSearch index fed from the database. To keep it in sync without dual writes, changes flow through change data capture into a Kafka topic, the pattern from Logs, Kafka, and Stream Processing. The same topic feeds view counts and seller analytics later, without touching the request path.
Checkout. This is the deep dive. Design a Payment System gives you the provider flow, idempotency keys, and a double-entry ledger. Creating the order, reserving the item, and charging the card span services, so Sagas, Outbox, and Two-Phase Commit applies: the order service writes the order and an outbox row in one transaction, a relay publishes the event, and a saga releases the item if the charge fails. Two buyers clicking "Buy" on the same one-off item is the contention problem from Design Ticketmaster, solved the same way, with a single conditional update on the item row.
Side effects. "Your item sold" emails and push messages go on a queue, not the request path. Message Queues gives you retries, a dead letter queue, and idempotent consumers, and Design a Notification System adds preferences and per-channel rate limits.
Keeping it up. Timeouts, Retries, and Circuit Breakers wraps the payment provider and search calls in timeouts, retries with jitter, and a circuit breaker, so a slow search cluster degrades to "results unavailable" instead of taking the listing pages down with it. Observability, SLIs, and SLOs turns the 300 ms goal into an SLO with a burn-rate alert, and traces show which hop is slow. Multi-Region and Disaster Recovery sets an RPO and RTO, keeps tested backups in a second region, and starts with warm standby rather than active-active, because one region in Europe is enough for now. Consensus and Leader Election is what keeps the Postgres failover and the Kafka controller from ever running two leaders.
Notice that no lesson stood alone. The estimate decided that caching mattered, the cache decided what consistency you could promise, and the outbox made search and notifications safe to add. That is system design in practice: each choice sets up the next.
Check yourself
Five million daily users each make 20 requests. What are the average QPS and a rough peak at three times the average?
daily = 5_000_000 * 20 avg = daily // 86_400 print(avg, avg * 3)
With N = 3 replicas, which read and write quorum pairs guarantee a read sees the latest write?
n = 3 pairs = [(1, 1), (2, 2), (1, 3), (2, 1)] print(*[r + w > n for r, w in pairs])
Match each problem to the building block that solves it.
Put the steps of a design interview in a sensible order.
- Tap the steps below in the right order.
What you can do now
- Turn a vague prompt into functional and non-functional requirements written as numbers.
- Estimate QPS, storage, and bandwidth in a few minutes and use them to justify choices.
- Draw a sensible high-level design with an edge, stateless services, caches, a database, queues, and object storage, and explain why each box is there.
- Choose a database, a shard key, an ID scheme, and a consistency level, and say what each costs.
- Keep data correct across services with idempotency keys, the outbox, and sagas.
- Plan for failure with timeouts, retries, circuit breakers, SLOs, and a disaster recovery strategy.
- Walk through any of the classic interview prompts in 45 minutes.
That is solid mid-level design skill and strong interview preparation. What it is not yet is experience: operating a large system through a real incident teaches lessons no diagram can. Treat these designs as starting points you will refine on the job.
Mistakes that still catch people
- Designing before asking. Jumping to Kafka and Cassandra before knowing the numbers. Revisit What Is System Design and Back-of-the-Envelope Estimation.
- Trusting the cache as the truth. Serving a stale price at checkout, or racing a delete with a slow reader. Revisit Caching and Design a Distributed Cache.
- Dual writes. Writing to the database and a queue or search index separately and assuming both succeed. Revisit Sagas, Outbox, and Two-Phase Commit and Search and Inverted Indexes.
- Retries without idempotency. A retried payment or message that runs twice. Revisit Consistency and CAP and Design a Payment System.
- A bad shard key. Sharding a celebrity, a hot event, or a hot ad onto one machine. Revisit Replication and Sharding and Design Ad Click Aggregation.
- Backups nobody has restored. A disaster recovery plan that has never been tested. Revisit Multi-Region and Disaster Recovery.
Where to go next
The natural next course is Docker: every box you drew here runs in a container, and packaging services is the first step to running them. After that, AWS maps these building blocks to real managed services, such as load balancers, queues, object storage, and managed databases. If interviews are close, Interview Prep puts this course under a clock alongside coding and behavioural rounds.
Real practice matters as much as the next course:
- Build a small version of one case study. A URL shortener or rate limiter with Postgres, Redis, and a queue, load-tested until something breaks, teaches more than reading about it.
- Read engineering blogs and postmortems. Public incident reports from large companies show these failure modes in real systems.
- Read the official docs. The Postgres, Redis, and Kafka documentation explain the guarantees each system really makes, which is what design reviews argue about.
- non-functional requirement
- A target for how well the system works, such as latency, availability, or durability, written as a number you can design against.
- cache-aside
- A pattern where the app reads the cache first, loads from the database on a miss, and fills the cache itself.
- shard key
- The field that decides which machine owns each row, and so decides whether load spreads evenly or piles onto a hot shard.
- idempotency
- The property that doing an operation twice has the same effect as doing it once, which makes retries safe.
- transactional outbox
- Writing an event to a table in the same transaction as the data change, then publishing it, so the two never disagree.
- SLO
- A service level objective: a target for a user-facing measure, such as 99.9% of requests under 300 ms, that sets an error budget.
- blast radius
- How much of the system and how many users one failure can affect, which cells, bulkheads, and regions keep small.