HELM
Ch 03 · System Design Fundamentals
Chapter 03 · The bedrock

System Design — the trade-offs you'll be measured on

A tech lead does not design systems by recalling famous architectures. They reason from first principles — latency budgets, throughput math, consistency models, failure modes. This chapter is the toolkit: numbers to memorise, models to reach for, and the patterns that work at any scale.

3.1 · Functional vs non-functional requirements

FunctionalNon-functional ("the -ilities")
"User can place an order""99.95% available, p95 < 200ms, 10k RPS peak"
"Admin can refund""PII encrypted at rest; audit log immutable for 7 years"

Junior engineers think functional. Tech leads think NFR-first — because the architecture you pick is determined by the SLO, not the feature list.

3.2 · Numbers every TL knows by heart

OperationOrder of magnitude
L1 cache reference0.5 ns
Branch mispredict5 ns
L2 cache reference7 ns
Main memory reference100 ns
Read 1MB sequentially from RAM~10 μs
SSD random read~150 μs
Round trip in same data centre~0.5 ms
Round trip across continents~150 ms
HDD seek~10 ms

These (Jeff Dean's classic table, modernised) let you reject bad designs on the spot. If a request must do 200 sequential cross-region calls, no caching scheme saves it.

3.3 · Latency, throughput, capacity

TermDefinition
LatencyTime for one request. Report as p50 / p95 / p99 — never as the average.
ThroughputRequests handled per second (RPS) or per minute (RPM).
CapacityMax throughput before latency violates the SLO.
BandwidthBytes per second a link can move.
ConcurrencyRequests in-flight at the same time.
Little's Law$L = \lambda \cdot W$ — in-flight requests = arrival rate × time-per-request.
Use Little's Law constantly
"4000 RPS at 100ms latency → ~400 concurrent in-flight requests, so plan thread/connection pools, DB connections, and queue sizes around that number."

3.4 · CAP & PACELC

CAP — pick 2 during partition Consistency Availability Partition tolerance CP — strong consistency, may reject AP — always responds, may diverge

CAP says: in a partition, you must choose Consistency or Availability. PACELC extends it: else, in normal operation, you also trade Latency vs Consistency. Dynamo-style stores are AP/EL; Spanner is CP/EC.

3.5 · Consistency models — strongest to weakest

ModelGuaranteeExample store
Linearizable / StrictAll ops appear in real-time order. Reads see latest write.Spanner, etcd, Zookeeper
SequentialAll clients see the same global order; not necessarily real-time.Kafka per-partition
CausalIf A happens-before B, all clients see A before B.Bayou, Riak
Read-your-writesYou see your own writes; others may not yet.Most session-stickied systems
Monotonic readsYou never see "older" data after seeing newer.Many caches
EventualIf writes stop, replicas converge.DynamoDB default, Cassandra

3.6 · Scaling — vertical, horizontal, partitioning

ApproachWhat you doWhen
VerticalBigger box.Single-leader DBs early; simplest first.
HorizontalMore boxes behind a load balancer.Stateless services.
Read replicasReplicate primary; serve reads from replicas.Read-heavy workloads; tolerate replica lag.
Sharding / partitioningSplit data by key (hash, range, geo).Once one box can't hold the data.
FederationSplit by function (users DB, orders DB).Diff teams own diff services.
CQRSDifferent models for read vs write.Complex domains; different access patterns.

Sharding strategies

  • Hash: shard = hash(key) % N. Uniform distribution; resharding is painful.
  • Range: contiguous key ranges per shard. Easy range queries; hotspots if traffic is skewed.
  • Geo: per region. Best latency; cross-region queries are slow.
  • Consistent hashing: minimises movement when adding/removing nodes; default in Cassandra, Dynamo.

3.7 · Caching strategies

PatternHow it worksWatch out
Cache-aside (look-aside)App checks cache; on miss → DB → fill cache.Stale reads; thundering herd on cold cache.
Read-throughCache library hits DB on miss.Same as above; tighter coupling.
Write-throughWrite to cache and DB synchronously.Slower writes; consistent reads.
Write-behindWrite to cache; async flush to DB.Risk of data loss on crash.
Refresh-aheadPre-fetch keys near expiry.Extra load; great for hot keys.
Negative cacheCache "not found" results.Prevents cache stampede for missing keys.

Eviction: LRU (default), LFU (hot keys), FIFO, TTL. Invalidation: TTL, write-through, event-based (CDC).

3.8 · Rate limiting & back-pressure

AlgorithmHow
Token bucketBucket refills tokens at rate $r$; each request consumes one. Bursts allowed up to bucket size.
Leaky bucketQueue of fixed size; processed at constant rate.
Fixed windowN requests per window. Simple; boundary bursts possible.
Sliding windowSmoothed rate; more accurate.

Back-pressure is the system telling upstream "slow down". HTTP 429, gRPC RESOURCE_EXHAUSTED, Kafka consumer pause, Reactive Streams demand. Always propagate; never silently drop.

3.9 · Failure modes & resilience patterns

Retry with jitter

Exponential backoff + randomness; never naked retry.

Timeout

Every network call has one. Default is wrong.

Circuit breaker

Open → half-open → closed. Stops cascading failure.

Bulkhead

Isolate pools so one slow dependency can't drain all threads.

Graceful degradation

Serve stale cache; hide non-essential features.

Idempotency keys

Safe retries on side-effectful ops.

Dead-letter queue

Catch poison messages without losing them.

Chaos testing

Kill instances on purpose so prod surprises don't.

3.10 · The whiteboard rubric — design any system in 6 steps

  1. Clarify — functional + NFR. Numbers: users, RPS, data size, latency.
  2. Capacity estimate — back-of-envelope. RPS × payload × growth.
  3. API surface — sketch the endpoints / events / message shapes.
  4. Data model — entities, access patterns, consistency needs.
  5. Architecture — services, DBs, caches, queues, edge. Draw the diagram.
  6. Trade-offs & failure modes — what breaks first; how you'd evolve in 6 months.

3.11 · Self-check

Q1 · Your service runs 5000 RPS with 200ms p95. How many in-flight requests should you size for?
~ 50
~ 1000
~ 10,000
Depends on the language
Q2 · You need cross-region writes and you can never lose data. CAP-wise you must accept…
Worse latency only
Reduced availability during partitions
Reduced throughput
You can have all three