Skip to content

Case studies: recap and quiz

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.

The same seven questions work for every design in this module, and for a design you have never seen.

  1. 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)
  2. 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)
  3. 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)
  4. 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)
  5. 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)
  6. 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)
  7. 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)

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.

Case study The earlier lessons it leaned on
URL shortener Requests per second, cache-aside, when the cache fails, stale reads
Pastebin Storage and retention, CDNs and edge caching, TTL and invalidation, choosing a shard key
File storage Bandwidth, cross-shard queries, polling and long polling, sagas
Notification system Delivery semantics, retries and dead letters, idempotent consumers, backoff and jitter
Chat Server-sent events and WebSockets, offsets and replay, consistent hashing, physical clocks
Social feed Hot keys, backpressure, the transactional outbox, hot shards
E-commerce Sagas, idempotency keys, locks and row versions, Little’s Law
Payment system Duplicate requests, ACID and the transaction, delivery semantics, what exactly-once means
Ride sharing Partition strategies, hot shards, hot keys, server-sent events and WebSockets
Video platform CDNs and edge caching, retries and dead letters, autoscaling, Little’s Law
Live streaming TCP and UDP, cache stampede, overload and load shedding, CDNs and edge caching
Global messaging Why go multi-region, replication and conflicts across regions, logical clocks, leases and fencing
Search engine Partition strategies, cross-shard queries, percentiles and tail latency, TTL and invalidation
Object storage Synchronous and asynchronous replication, quorums, storage and retention, consistency models

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.

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.
  1. Line 1 of 12One account in 1,000 has a million followers, and its posts cause most of the writes.
  2. Line 2 of 12Opening the app is one lookup, because each user's list was written when the posts were made.
  3. Line 3 of 12When the workers fall behind, some users see an older list, but nobody gets an error.
  4. Line 4 of 12A client times out and sends the same request again, and the customer must be charged once.
  5. Line 5 of 12A refund is written as a new entry, never as a change to an old one, and the entries must add up.
  6. Line 6 of 12A report from the card network is compared with our own records to find the differences.
  7. Line 7 of 12100,000 phones each report their position every 4 seconds, and the data is only about 10 MB.
  8. Line 8 of 12The nearest driver may be in the cell next to the rider's, so a search reads the neighbouring cells too.
  9. Line 9 of 12Two riders must not be offered the same driver at the same moment.
  10. Line 10 of 12An object is cut into 10 data fragments and 4 parity fragments, and any 4 of the 14 may be lost.
  11. Line 11 of 12A GET right after a PUT must find the object, so a majority of a small group of machines must agree it exists.
  12. Line 12 of 12A crash between writing the bytes and recording the object leaves an orphan to collect.

Check your answers at least once before looking at the answers.

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.

Question 1 of 5

The URL shortener's second stage (a Redirect API, a cache, a database and a key counter) runs at 10 times its design load, 10,000 requests per second. The Redirect API is asked for 10,000 per second and can do 8,000. The cache is asked for 7,920 of 40,000. The database is asked for 476 of 800. The key counter is asked for 80 of 333.

Which component is the bottleneck?

Choose one answer.

Question 2 of 5

The chat's second stage (messages partitioned by conversation in a store of 40 nodes) runs at 3 times its design load, 3,000 messages per second. The single chat server is asked for 3,000 per second and can do 2,667. The store receives the 2,667 that get through, out of 106,667 writes per second. At the peak, 2 million phones are connected, and one server holds far fewer connections than that.

Which step comes next?

Choose one answer.

Question 3 of 5

The payment system's second stage (idempotency keys added) runs at 3 times its design load, 900 attempts per second. The fee account, one row updated one transaction at a time, is asked for 720 updates per second and can do 333. The database is asked for 2,340 of 4,000 queries per second. The key store is asked for 900 of 16,000. The card network connection is asked for 720 of 15,000.

Which step comes next?

Choose one answer.

Question 4 of 5

The social feed's third stage (celebrity posts merged at read time) runs at 10 times its design load, 70,000 requests per second. The timeline store is asked for 209,300 operations per second and can do 160,000. The celebrity store is asked for 69,300 of 80,000. The API servers are asked for 70,000 of 85,333. The fan-out service is asked for 700 of 3,200.

Which component is the bottleneck?

Choose one answer.

Question 5 of 5

The object storage's third stage (three copies of every object) runs at 2 times its design load, 16,000 requests per second. The metadata database is asked for 16,000 queries per second and can do 12,000. The 30 storage nodes are asked for 19,200 disk operations per second and can do 24,000. The API servers are asked for 16,000 of 128,000.

Which component is the bottleneck?

Choose one answer.

Case studies: module quiz

This quiz needs JavaScript to check your answers.

Question 1 of 10

A URL shortener receives 1,000 requests per second. 99 in every 100 are redirects and 1 in every 100 is a new link. A cache answers 95% of the redirects, and every new link goes to the database.

About how many queries per second reach the database (the cache misses plus the new links)?

Enter a number and choose its unit.

queries per second
Question 2 of 10

A pastebin first keeps each paste, about 10 KB, as a row in its database. Why does the next design keep the text in object storage and only the details in the database?

Choose one answer.

Question 3 of 10

At 3,000 notifications per second, 900 are emails, and the only email provider accepts 800 per second. A queue already sits between the API and the senders.

What removes the limit?

Choose one answer.

Question 4 of 10

In a social feed every post is written into the timeline of each follower. One account in 1,000 has a million followers, and that account causes 83% of the timeline writes.

What does the design do about those accounts?

Choose one answer.

Question 5 of 10

At 10 times the design load, 120 checkouts are in flight at any moment, each waiting on the payment provider. Run as one synchronous request each, they fill 94% of 128 request slots.

Why does running the checkout as a saga help?

Choose one answer.

Question 6 of 10

A client sends a payment, the connection drops before the answer arrives, and the client sends the same payment again. At 300 attempts per second, 60 are retries like this one.

What stops the second charge?

Choose one answer.

Question 7 of 10

A ride-sharing service has 100,000 drivers online. Each one reports its position every 4 seconds.

How many location updates per second does the service receive?

Enter a number and choose its unit.

updates per second
Question 8 of 10

A live stream's newest segment exists for only a few seconds, and the viewers of every edge server ask for it at the same moment. With 90% of the requests answered at the edge, the origin still receives 9,000 requests per second at 90,000.

What brings the origin's load down to about 900 per second?

Choose one answer.

Question 9 of 10

A chat runs a stack in each of three regions and copies messages between them through a relay. Members of one conversation who are in two regions see its messages in different orders.

What gives everyone one order?

Choose one answer.

Question 10 of 10

An object store writes the bytes to data nodes and then records the object in a metadata service. A client does a PUT and, right after, a GET for the same object.

Why does the GET see the object, and what does a crash between the two writes leave behind?

Choose one answer.

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.