3.1 · Functional vs non-functional requirements
| Functional | Non-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
| Operation | Order of magnitude |
|---|---|
| L1 cache reference | 0.5 ns |
| Branch mispredict | 5 ns |
| L2 cache reference | 7 ns |
| Main memory reference | 100 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
| Term | Definition |
|---|---|
| Latency | Time for one request. Report as p50 / p95 / p99 — never as the average. |
| Throughput | Requests handled per second (RPS) or per minute (RPM). |
| Capacity | Max throughput before latency violates the SLO. |
| Bandwidth | Bytes per second a link can move. |
| Concurrency | Requests in-flight at the same time. |
| Little's Law | $L = \lambda \cdot W$ — in-flight requests = arrival rate × time-per-request. |
3.4 · CAP & PACELC
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
| Model | Guarantee | Example store |
|---|---|---|
| Linearizable / Strict | All ops appear in real-time order. Reads see latest write. | Spanner, etcd, Zookeeper |
| Sequential | All clients see the same global order; not necessarily real-time. | Kafka per-partition |
| Causal | If A happens-before B, all clients see A before B. | Bayou, Riak |
| Read-your-writes | You see your own writes; others may not yet. | Most session-stickied systems |
| Monotonic reads | You never see "older" data after seeing newer. | Many caches |
| Eventual | If writes stop, replicas converge. | DynamoDB default, Cassandra |
3.6 · Scaling — vertical, horizontal, partitioning
| Approach | What you do | When |
|---|---|---|
| Vertical | Bigger box. | Single-leader DBs early; simplest first. |
| Horizontal | More boxes behind a load balancer. | Stateless services. |
| Read replicas | Replicate primary; serve reads from replicas. | Read-heavy workloads; tolerate replica lag. |
| Sharding / partitioning | Split data by key (hash, range, geo). | Once one box can't hold the data. |
| Federation | Split by function (users DB, orders DB). | Diff teams own diff services. |
| CQRS | Different 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
| Pattern | How it works | Watch out |
|---|---|---|
| Cache-aside (look-aside) | App checks cache; on miss → DB → fill cache. | Stale reads; thundering herd on cold cache. |
| Read-through | Cache library hits DB on miss. | Same as above; tighter coupling. |
| Write-through | Write to cache and DB synchronously. | Slower writes; consistent reads. |
| Write-behind | Write to cache; async flush to DB. | Risk of data loss on crash. |
| Refresh-ahead | Pre-fetch keys near expiry. | Extra load; great for hot keys. |
| Negative cache | Cache "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
| Algorithm | How |
|---|---|
| Token bucket | Bucket refills tokens at rate $r$; each request consumes one. Bursts allowed up to bucket size. |
| Leaky bucket | Queue of fixed size; processed at constant rate. |
| Fixed window | N requests per window. Simple; boundary bursts possible. |
| Sliding window | Smoothed 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
- Clarify — functional + NFR. Numbers: users, RPS, data size, latency.
- Capacity estimate — back-of-envelope. RPS × payload × growth.
- API surface — sketch the endpoints / events / message shapes.
- Data model — entities, access patterns, consistency needs.
- Architecture — services, DBs, caches, queues, edge. Draw the diagram.
- Trade-offs & failure modes — what breaks first; how you'd evolve in 6 months.