Lesson 57 — System Design I: Scale, Latency, CAP

~25 minutes · Day 75 · system design

Tonight's interview shape is the first system-design conversation: a small service gets popular, one machine starts struggling, and the interviewer wants to hear how you think before any code exists. The win is not naming fancy tools. The win is drawing the boxes, finding the bottleneck, and saying the trade-off clearly.

The invariant

You scale up with a bigger box or out with more boxes; once data lives on more than one box, a network partition forces the CAP choice between consistency and availability.

That sentence is the whole lesson. App servers are usually easy to clone because they should be stateless. Data is harder: the moment two machines can answer for the same data, the network between them becomes part of the correctness story.

The script

Use the same seven steps every time: requirements → estimate scale → API → data model → high-level boxes → deep-dive the bottleneck → failure modes. For scaling basics, apply it like this:

  1. Requirements: users can read items and create orders; reads should feel fast, writes should not lie.
  2. Estimate scale: separate read traffic from write traffic; reads usually grow first and are easier to cache.
  3. API: sketch simple endpoints such as GET /items/:id and POST /orders.
  4. Data model: name the core tables or documents: users, items, orders.
  5. High-level boxes: client, load balancer, stateless app servers, cache, primary database, replica.
  6. Bottleneck: the database is stateful, so scaling it changes latency and correctness.
  7. Failure modes: app crash, cache miss, database overload, replica lag, network partition.

Notice the order. You do not start with Kafka, Kubernetes, or ten databases. Start with the user promise, then add machinery only where the pressure appears.

The architecture diagram

Scaling architecture with a CAP partition point Users send requests through a load balancer to three stateless app servers. The apps read through a cache and write to a primary database that replicates to another database. A partition line between the databases marks the CAP choice. Scale out the stateless layer; be careful when the data layer splits. Users browser/app Load balancer spreads traffic App server A App server B App server C more boxes = scale out Cache fast repeated reads Primary DB writes land here Replica DB read copy scale up = bigger database machine network partition CAP: wait for consistency or answer for availability
The interesting line is not the load balancer. It is the broken link between data copies.

The bottleneck deep-dive

The database is the bottleneck because it owns truth. Three named choices cover most beginner scaling answers:

CAP appears only when a partition happens. If the primary and replica cannot talk, a consistent design waits, rejects, or routes to the side that knows the latest write. An available design answers from whatever side is reachable, then accepts that the answer may be stale and needs repair later. The formal CAP result is about this partition moment, not a magic excuse for every slow system (CAP theorem overview).

Numbers that matter

FigureWhy it mattersSource
100 msFeels roughly instant to a user; great target for common reads.NN/g response limits
1 secondStill keeps the user in flow, but the delay is noticed.NN/g response limits
200 µsTypical 1 Gbit/s network latency cited for a Redis client round trip.Redis latency guide
99.9%About 8.8 hours of allowed downtime per year; each required component lowers the total.ACM Queue on BASE

The table is not for memorizing trivia. It teaches the interview habit: turn vague words like “fast” and “reliable” into rough numbers before choosing boxes.

Practice — answer before you scroll past

1. A single database box is near CPU limit. Which first move preserves the simplest consistency story?

2. During a network partition, what does CAP force you to choose between?

3. Which design makes reads fast but risks stale data?

4. For a beginner design answer, what is the safest order?

Your move (tonight)

No LeetCode for this lesson. Redraw the architecture diagram from memory on paper, then explain the whole design out loud in 5 minutes as if to an interviewer. Use this exact spine: requirements → estimate scale → API → data model → high-level boxes → deep-dive the bottleneck → failure modes.

For the encode step, write one line in your Notion tracker: where you would scale up, where you would scale out, and what you would do during a database partition.

One primary source

Read System Design Primer — Scalability after your redraw, as the compare step. Find the first place where its trade-off language is sharper than yours.