Case studies: recap and quiz
The fourteen designs side by side
Section titled “The fourteen designs side by side”Each row is a case study. The second column is the figure, from its lab or its estimate, that made the simplest design give way and forced the first scaling step. The other two columns are the pattern the design is built around and the price it pays. Every figure is illustrative model output from the lab: it compares designs, and it is not a benchmark.
| Case study | The number that forced the first step | The central pattern | The main trade-off |
|---|---|---|---|
| URL shortener | At 1,000 requests per second one database is at 125% of its 800 queries per second | Cache-aside in front of the lookups, then replicas for the misses | A second system to run, and a stampede when the cache is empty |
| Pastebin | At 1,000 requests per second a database that holds the text is at 220% | The text in object storage and the details in a database, with expiry in three layers | Two systems, an order of writes, and orphans to collect |
| File storage | At 300 requests per second the disk is at 198%: 132 transfers per second against the 67 it can do | Chunks of 4 MiB named by their hash, with the metadata committed last | A row of metadata for every chunk, and hashing on the client |
| Notification system | At 300 notifications per second, two servers held for about 128 ms each are at 120% of the 250 per second they can do | A queue and workers, then a delivery log that claims each send | A notification is accepted before it is delivered, and at-least-once delivery brings duplicates |
| Chat | At 1,000 messages per second one database is at 125% of its 800 writes per second | Messages partitioned by conversation, so the partition numbers them, then gateways and a registry | One conversation is limited by one node |
| Social feed | At 1,200 requests per second building the feed on read puts the database at 150% of its 800 queries per second | Fan-out on write, except for accounts with a huge following, whose posts are merged at read time | Two paths to keep correct, and a threshold to tune |
| E-commerce | At 2,100 requests per second one database is at 139% of its 1,600 queries per second | A cached catalog, stock held by an expiring reservation, and a checkout run as a saga | Pending orders, compensations and intermediate states |
| Payment system | At 300 attempts per second the fee account is at 90% of its 333 updates per second, and 60 of the 300 are retries | An idempotency key on every attempt, a double-entry ledger and reconciliation | A lookup on every attempt, and keys kept for at least 24 hours |
| Ride sharing | At 900 requests per second positions kept in a database put it at 86% of its 2,000 queries per second | An index of positions in memory, split by grid cell | Empty after a restart, so searches miss drivers for a few seconds |
| Video platform | One server fills its 10 Gbit/s link at 250 segments of 40 Mbit per second | Object storage, a CDN, a ladder of qualities and workers that follow the queue | Compute for every upload, and about twice the storage |
| Live streaming | 10 streams against the 8 encoder slots of one server | Encoding apart from delivery, and a CDN whose edge servers collapse requests for the same segment | Capacity paid for before the peak, and a failed encoder cuts the stream |
| Global messaging | A peak of about 200,000 messages per second against the 106,667 that one stack takes | A stack in each region, an asynchronous relay, a home region for each conversation | A round trip for members who are not in the conversation’s home region |
| Search engine | One server answers 800 queries per second and the target is 2,000 | An inverted index in shards, copies for throughput, a results cache and tiers | Every query visits every shard, so a slow shard slows the query |
| Object storage | One server does 800 requests per second and the design load is 5,000 | Metadata apart from the data, copies or erasure coding, metadata committed by a majority | Three times the bytes with copies, or 10 operations per read with erasure coding |
Read down the second column: each figure sets a load against the capacity of one component, which is how the simplest design shows that it will not last. Whatever the system, the method does not change: find the figure, name the component it belongs to, and change one thing.
A checklist for an interview-style design
Section titled “A checklist for an interview-style design”The same seven questions work for every design in this module, and for a design you have never seen.
- What must it do, what must it never do, and which numbers matter? Write down the rule that is never allowed to break: no second charge, no lost message, no oversold item. (Payment system, Chat)
- What do the numbers say? Turn the volume into requests per second at the average and at the peak, into storage and into bandwidth, and say which of the three the design is built around. (URL shortener, Ride sharing, Video platform)
- What is the simplest design that works? Usually one application and one database. Compute each component’s share of its own capacity at the design load. (URL shortener)
- Which component breaks first, and at what load? Judge a component by the share of its own capacity, not by how big its count looks: the busiest node in absolute terms is often not the one over its limit. (Object storage)
- What is the one change that removes that limit? Name what it costs and what breaks next, then repeat. A design is a list of stages, each forced by a number. (Social feed)
- What happens when a part is lost? Lose the cache, a worker, a region or a disk, and say what the numbers become and what limits the damage. (Live streaming, Global messaging)
- What did each decision cost, and when would you choose the other side? For each, say what it gains, what it costs and when the opposite is better. (Search engine)
What each case study leaned on
Section titled “What each case study leaned on”None of the case studies invents a technique. Each one is the earlier modules put to work, and the table below shows which lessons carry the most weight for each case.
Several lessons come back more than once. The CDN lesson carries the pastebin, the video platform and live streaming, and the hot-key and hot-shard lessons carry the social feed and ride sharing. Idempotency appears in the notification system, e-commerce and the payment system. That repetition is the point of the module: a small number of ideas, applied to different loads, give most of the designs.
Sort the problems
Section titled “Sort the problems”Four case studies, twelve statements. Put each statement under the case study it belongs to.
Challenge
Which case study?
Four of the fourteen case studies have a problem that shows up nowhere else in the same way. Read each statement and put it under the case study whose design it belongs to.
Sorting needs JavaScript.
Categories
- Social feed
- Feeds built from the posts of the accounts a user follows.
- Payment system
- Money that moves, with retries and records that must add up.
- Ride sharing
- Drivers on a map, reporting their position all the time.
- Object storage
- Objects that must survive the loss of disks, with a service that knows where each one is.
Check your answers at least once before looking at the answers.
Check your understanding
Section titled “Check your understanding”The first quiz gives the figures of a stage and asks which component is the bottleneck, or which step comes next. The second mixes the case studies, with questions on estimation, patterns and failure. Every option is explained, whether it is right or wrong.
Read the bottleneck
This quiz needs JavaScript to check your answers.
Case studies: module quiz
This quiz needs JavaScript to check your answers.
Where this goes next
Section titled “Where this goes next”The next module, the Interview Arena, turns the same designs into timed mock interviews with scripted follow-up questions. Use the checklist above as the outline of your answer, and remember that a design you can defend, with its numbers and its costs, is worth more than a diagram with more boxes.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.