Tech

System design

Size a system on the back of an envelope, then make it fast with caches, reliable with replicas and safe with retries, and explain each trade-off the way design interviews expect.

6 concepts7 min read25-question test, from a bank of 33Updated

Concept 1 of 61 min

Back-of-the-envelope sizing

The rule
Size a system for its peak: daily requests ÷ 86,400 seconds × the peak factor, and storage = items a day × size × days kept × replicas.
Worked examples

Requests a second

Given
Users8,000,000
Requests each30 a day
Seconds a day86,400
Peak4 times average
  1. A day = 8,000,000 × 30 = 240,000,000
  2. Average = 240,000,000 ÷ 86,400 ≈ 2,778
  3. Peak = 2,778 × 4 ≈ 11,111

Size for about 11,111 requests a second at peak, not the 2,778 average.

Storage over 3 years

Given
Documents a day1,000,000
Size2 MB
Days a year365
Years3
Replicas2
  1. A day = 1,000,000 × 2 = 2,000,000 MB
  2. That is 2 TB a day
  3. Total = 2 × 365 × 3 × 2 = 4,380 TB

About 4.4 PB, so storage, not traffic, drives the design.

Video bandwidth

Given
Viewers200,000
Stream8 Mbit/s
  1. Total = 200,000 × 8 = 1,600,000 Mbit/s

1.6 Tbit/s at once, which only a content delivery network can serve.

The picture
Formula
Peak requests/s=users × requests a day ÷ 86,400 × peak factor
storage=items a day × size × 365 × years × replicas
bandwidth=viewers × bitrate
Why it holds

Bandwidth counts in bits, 8 to a byte. Know the orders of magnitude: about 100 ns for a main-memory read, 100 µs for a random 4 KB SSD (solid-state drive) read, 80 ms for a transatlantic round trip.

Interviewers want the method and a sensible order of magnitude, not decimals. Sizing on the average leaves the system down every evening.

Forgetting replicas, or counting the original twice, is the usual storage slip. Video bitrates are quoted in bits per second while disks are in bytes, which is a factor of 8.

A random SSD read is about 1,000 times slower than memory and a transatlantic round trip nearly a million times, which is why caches, and data kept close to users, matter.

Watch out
  • Sizing for the average instead of the peak.
  • Forgetting the replicas in storage.
  • Confusing bits and bytes.
In the interview
  1. Design a service that stores every trade a bank books for 7 years. Where would you start?

    A complete answer covers

    • Estimate trades a day, size per trade and peak bursts.
    • Work out storage over 7 years with replicas.
    • Ask about read patterns: audits, regulators, daily reports.
    • Then choose storage tiers: recent data fast, old data cheap but searchable.

Also in our technical interviews, on camera, with a score.

Concept 2 of 61 min

Caching: hit rates, expiry, stampedes and hashing

The rule
A cached read pays the lookup every time plus the database on each miss, and a time-to-live should match the staleness the business accepts.

The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.

See the plansSign in

Concept 3 of 61 min

Replicas, consistency and availability

The rule
Replicas lag the primary, so a user's own writes are read from the primary, read-your-writes on top of eventual consistency.

The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.

See the plansSign in

Concept 4 of 61 min

Retries, idempotency, queues and back-pressure

The rule
A retried payment needs an idempotency key stored by the server, and retries need exponential backoff with jitter and a circuit breaker that fails fast.

The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.

See the plansSign in

Concept 5 of 61 min

Queries, storage engines, IDs and service boundaries

The rule
Fetch related rows in one query instead of N+1, and page by keyset, WHERE id > last_seen_id, not LIMIT with a growing OFFSET.

The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.

See the plansSign in

Concept 6 of 61 min

AdvancedTail latency: why fan-out makes rare delays common

The rule
A request waiting on N servers each slow 1% of the time is slow with probability 1 − 0.99N.

The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.

See the plansSign in

Recap

  • Size for the peak: requests a day ÷ 86,400 × peak factor; storage × days × replicas; bandwidth in bits, not bytes.
  • Average cache read = lookup + miss rate × database time; expire with a TTL (time to live) that matches the staleness you accept; let one request rebuild a hot key.
  • Replicas lag: read your own writes from the primary; under a partition choose consistency or availability; series multiply availabilities, redundancy multiplies failures.
  • Retries need idempotency keys, backoff with jitter and circuit breakers; queues absorb slow work but grow when consumers fall behind.
  • Shard by a hash, page with keysets, fetch in batches, not N+1, and keep a small team on a monolith.
Now test it

25 questions on System design

Timed, like the real one, drawn from a bank of 33. Every answer explained.

Test yourself →