Skip to content
About
Main content

Scenarios

Longer problems, like those in senior system design interviews. A strong answer estimates with numbers first, names the mechanism, then recommends a fix and says what it costs.

Try each one before you open the answer.
1You must scan 50 TB of event data, stored as Parquet on S3, within 5 minutes. Is that feasible, and what would you build?Show the answer

Estimate

One connection to S3 delivers about 80 MB/s, so 50 TB ÷ 80 MB/s = 625,000 connection-seconds. In 300 seconds that needs about 2,100 parallel streams and about 170 GB/s of total network (2,100 × 80 MB/s).

Check the limits

One machine cannot receive 170 GB/s: a 100 Gb/s network card gives 12.5 GB/s. So at least 14 machines are needed for the network alone; with decompression and memory bandwidth added, more like 30–50.

Design

About 40 nodes, each running 50–100 concurrent range GETs of 8–64 MB, spread across many key prefixes to stay under per-prefix request limits (which return 503 errors). Read only the needed columns, so fewer bytes cross the network at all.

Trade-offs

Cost (per-request pricing and egress), time for S3 to split busy prefixes, and stragglers: hedge slow requests by sending a duplicate.

Conclusion

Feasible, but it is a multi-node network-bandwidth problem, not a storage problem.

Read moreBack-of-the-envelope estimationObject storageThe roofline modelTail at scale

2Your service reads from 40 shards for every request, and its SLO is p99 below 100 ms. Each shard has a p99 of 50 ms and a p50 of 5 ms. Will you meet the SLO? If not, how do you fix it?Show the answer

Estimate

The chance that a request meets no slow shard (none slower than 50 ms) is , so 33% of requests are slow, not 1%. The service's is about the shards' p99.975, far above 50 ms. The SLO will very likely be missed.

Fix, in order of value

  1. Reduce fan-out: re-partition so a typical request touches about 8 shards (0.99⁸ ≈ 92% fast).
  2. Hedge: if a shard has not answered after 15–20 ms, send the request to a replica. A few percent more load buys a large tail improvement.
  3. Shrink each shard's own tail: find what makes shards slow, such as pauses, or a noisy neighbour. Slowness that hits many shards at once is worse than the formula assumes.
  4. Return partial results at a deadline, if the product allows it.

Warning

Hedging adds load. At high it can push the system past the knee of the queueing curve, so cap hedges at about 5% of requests and watch utilization.

Read moreTail at scaleThe queueing wall

3A write-heavy table on NVMe drives shows latency rising steadily over weeks, although traffic is flat and the disks are 60% full. What are your hypotheses, and how do you test them?Show the answer

Hypothesis 1

Write has grown. Over time free blocks fragment, the drive copies more live pages during garbage collection (, where v is the fraction of each erased block still live), and that background work steals bandwidth. Test: compare NAND writes with host writes over time, using smartctl.

Hypothesis 2

is not reaching the drive: a mount option, a virtualization layer or a RAID controller blocks it, so the drive believes it is nearly full. Test: check discard / fstrim, then measure again after running fstrim.

Hypothesis 3

The application mixes data of different ages in place, for example random updates in a B-tree-like layout, which drives amplification up.

Fixes

Over-provision more (leave 20–30% of the drive unpartitioned), run TRIM regularly, separate hot and cold data, or move to an LSM or another sequential write layout.

Read moreThe FTL and garbage collectionWrite amplification

4Your API's p99 is 150 ms at 60% CPU and 4 seconds at 85% CPU. A colleague suggests adding servers whenever CPU reaches 85%. How do you respond?Show the answer

Estimate

By , with S the service time and ρ the utilization: at ρ = 0.6, R = 2.5 S; at ρ = 0.85, R = 6.7 S on average, and the tail is much longer.

Diagnose

New servers take minutes to start. During those minutes the grows, clients time out and retry, and the arrival rate rises further. Scaling at 85% reacts after the knee of the curve, when the feedback loop has already started.

Recommend

  1. Scale at 50–60%, or on a leading indicator such as queue depth or concurrent requests (by , L = λW, concurrency rises before CPU does).
  2. Reduce variation in service time, for example by moving slow endpoints to their own pool; by , variability multiplies the wait.
  3. Add admission control and load shedding at the edge.
  4. Give retries a budget and add jitter.

Exception

Batch workers, where no one waits on a single request, can safely run at 95%.

Read moreThe M/M/1 resultKingman's formulaWhy 80% has already used up the budget

5Design the commit protocol for a data lake table on S3, so that two writers can safely add data at the same time.Show the answer

Constraints

S3 has no atomic update of several objects and no atomic rename; consistency is per object.

Design

Writers first upload their new data files. These are invisible until something references them, so uploading is safe to repeat. Each writer then writes a new metadata file describing the new table state, and commits with an atomic compare-and-swap on one pointer: a conditional write of a "current version" object, or a row in a catalog or a table such as DynamoDB.

Conflicts

If two writers race, one loses the swap. It re-reads the winner's metadata, checks whether they touched the same files or partitions, and retries if not.

Clean-up

Files left by failed writers are removed later by garbage collection. This is the general pattern for immutable storage: write new, switch one pointer, collect the old.

Failure modes

Retries must be idempotent. Garbage collection must not delete files that an in-flight writer has uploaded but not yet committed, so give it a grace period.

Read moreObject storageYou must decide before you know

6A product serves users in Mumbai and Virginia. Account balances need strong consistency, and users in both places want low latency. What are the options?Show the answer

Geometry first

A round trip between Mumbai and Virginia is about 200 ms, so any commit that needs both regions takes at least 200 ms.

Options

  1. A home region for each account, with its leader there: local users are fast, remote users pay about 200 ms per write, and reads can be served locally if slightly stale reads are acceptable.
  2. Synchronous consensus across regions (Spanner-style): strong consistency everywhere, at the cost of at least one inter-region round trip per commit. Acceptable only for low write rates, or if 100–300 ms writes are tolerable.
  3. Asynchronous replication with conflict resolution: fast everywhere but not strongly consistent, which is usually wrong for balances.

Recommend

Pin each account to a home region by its user's location, keep the across availability zones inside that region (1–2 ms apart), and replicate asynchronously to the other region for disaster recovery. Be explicit that strong consistency, low and active writes in several regions cannot all be had at once.

Read moreThe latency tiers

7A scatter-gather endpoint, where one coordinator queries many workers and gathers their replies, is fine at 10 workers but collapses at 150, with low network utilization. Walk through your diagnosis and fix.Show the answer

Diagnose

The symptoms point to , not bandwidth: low average utilization, a sharp jump in p999, and a clear link to the number of workers. Check switch-port drop counters, TCP retransmissions and timeouts (ss -ti, nstat), and whether the p999 values cluster near the retransmission timeout (200 ms, 1 s).

Fix, cheapest first

  1. Add a few milliseconds of random jitter to worker replies.
  2. Reduce fan-out (fewer, larger partitions), or aggregate in two levels so no single receiver hears from 150 senders.
  3. Enable ECN-based (DCTCP) and lower tcp_rto_min.
  4. Limit replies in flight with credits: the coordinator grants permission to send.

Why more parallelism fails

By the , past a certain number of workers each added worker reduces total .

Read moreIncastUniversal Scalability Law

8Management asks for a cache to make everything 10 times faster. How do you decide whether it will help?Show the answer

Ask first

Where is the time spent? A cache helps only if the same data is read repeatedly, and only if the slow path it avoids is the dominant cost.

Estimate

With hit ratio h, . With a 100 ms backend, a 10× gain needs h of at least 90%; at h = 50% the best possible gain is 2×.

The tail

is set by the misses, so p99 may not improve at all.

What it costs

The cost moves rather than disappears: to memory, to invalidation complexity and stale reads. And if the cache starts empty or fails, the backend receives its full load, possibly while already near the knee of its queueing curve.

Decide

Measure the hit ratio on a replay of real traffic before building anything.

Read moreLocality: two betsTail at scaleCosts are conserved

9How full should you run an SSD-backed, log-structured store?Show the answer

Estimate

Cleaning cost is bytes moved per byte freed, where u is utilization: 2.3 at 70%, 9 at 90%, 19 at 95%.

Decide

Choose the target utilization from your write-amplification budget and the drive's , not from capacity: headroom is write amplification bought in advance.

Watch

The trend: load growth pushes utilization towards the cliff.

Read moreWhat the collector costs