Volume 12 · Chapter 3 — Principal Software Architect Interview Mastery & Enterprise System Design Handbook
Large-Scale System Design Patterns
3.1 Introduction
“Design a system for millions of users” is the archetypal principal interview prompt. It is really a test of whether you know the standard building blocks of scale - horizontal scaling, load balancing, caching, database scaling, async processing - and can assemble them from requirements rather than by rote. This chapter is the pattern toolkit, framed for interview use. The meta-lesson: scale is achieved by removing shared bottlenecks and doing less work on the critical path.
3.2 The Scaling Toolkit
flowchart TB
U["Millions of users"] --> CDN["CDN (static + cached)"]
CDN --> LB["Load Balancer"]
LB --> S1["Stateless service instances (autoscaled)"]
S1 --> Cache["Distributed cache (Redis)"]
S1 --> Q["Async queue (offload heavy work)"]
S1 --> Pri[("Primary DB (writes)")]
S1 --> RR[("Read replicas (reads)")]
Pri -. "shard by key" .- Shards[("Shards")] 3.3 Horizontal Scaling and Statelessness
The foundation is stateless services scaled horizontally behind a load balancer, so capacity grows by adding instances and any instance serves any request. State moves to shared stores (Redis) or the client (tokens). Statelessness is what makes autoscaling, rolling deploys, and failover work - it is the enabling property for everything else.
3.4 Caching and CDNs
Caching is the highest-leverage scaling tool: it turns repeated expensive work into cheap lookups and shields backends. Layer it - CDN/edge for static and cacheable responses, distributed cache (Redis) for hot data shared across instances, and application caches - and address the hard parts: invalidation and stampede protection. Most traffic should never reach the origin.
3.5 Database Scaling
The database is the hardest thing to scale because it is stateful. Climb the ladder as load demands: optimize queries and indexes, add read replicas for read-heavy load, cache hot reads, partition/shard for write scaling, and adopt CQRS with a separate read store when read and write needs diverge. Each rung adds complexity, so justify each with measured need.
3.6 Asynchronous Processing
Offloading work to queues is a key scaling move: anything that does not need to happen in the request path (sending emails, generating reports, updating projections) goes to a background worker via a queue, keeping the synchronous path fast and absorbing bursts. This is how you keep p99 low under load.
How do you design a system to handle millions of users?
I build it from the scaling toolkit, driven by a capacity estimate, and the guiding idea is to remove shared bottlenecks and keep work off the critical path. First I estimate the load (requests per second at peak, read/write ratio, data volume) so I design for the right scale. Then: I make services stateless and scale them horizontally behind a load balancer, pushing state to Redis, so capacity grows by adding instances and failover is trivial. I offload traffic from the origin with layered caching and a CDN so most reads never hit the backend, addressing invalidation and stampede protection. I scale the data tier - usually the real limit - up a ladder: optimize queries and indexes, add read replicas for the read-heavy load, cache hot reads, and shard for write scale or adopt a CQRS read model when reads and writes truly diverge, taking each step only as measured need requires. I move non-critical work (notifications, reports, projections) off the request path into async queues and background workers, which keeps the synchronous path fast and absorbs bursts. I protect tail latency with rate limiting, timeouts, and circuit breakers so overload sheds gracefully, autoscale on real signals, and design for failure with redundancy across zones. Finally I make it observable and validate at target scale with load tests, watching p99 rather than averages. Throughout I name trade-offs - caching’s staleness, sharding’s complexity, eventual consistency on read models - and I only add each mechanism where the scale justifies its cost, because over-engineering for imaginary scale is as much a failure as under-provisioning.
What is the single highest-leverage technique for scaling a read-heavy system, and what are its pitfalls?
Caching is the highest-leverage technique for a read-heavy system, because it turns repeated expensive reads into cheap in-memory lookups and shields the backend from the bulk of the load - a good cache can absorb the large majority of reads so the database only handles misses and writes, often turning an impossible database load into a comfortable one. Layered well (CDN at the edge for cacheable responses, Redis for hot shared data, application caches), it is what lets a modest backend serve enormous read traffic. But its pitfalls are real and are where candidates get caught. Invalidation is famously hard: stale cache entries can serve wrong data, so you need a coherent strategy - TTLs, event-driven invalidation on writes, or write-through - matched to how much staleness the business tolerates. Cache stampedes occur when a popular entry expires and many requests miss simultaneously and all recompute, overwhelming the backend; you prevent this with per-key locking so only one caller recomputes, jittered expiration so keys do not expire together, and refresh-ahead for hot entries. There is also the risk of caching masking an underlying problem - an N+1 query or missing index that a proper fix would solve more cheaply - so I confirm caching is addressing genuine repeated reads, not papering over inefficiency. And caches add a consistency dimension and operational surface. So caching is the first tool I reach for to scale reads, but I design invalidation and stampede protection up front, decide the acceptable staleness deliberately, and make cache hit rate and backend load observable, because a naively added cache trades a scale problem for correctness and operational problems.
When do you introduce sharding, and what makes it risky?
I introduce sharding only when a single database’s write throughput genuinely cannot keep up even after exhausting the cheaper options - query and index optimization, read replicas to offload reads, and caching - because sharding is powerful but expensive and hard to reverse. The trigger is a measured write-scale ceiling, not anticipated growth that may never arrive. What makes it risky is several things. The shard key is a near-irreversible decision: it must distribute load evenly and align with the dominant access pattern, because a poor key creates hot shards that throttle even when total capacity looks adequate, and changing the key later means a painful data migration. Cross-shard operations become hard: queries and transactions spanning shards are slow and complex, so you lose the easy joins and multi-entity transactions a single database gives you. Operations get harder too - rebalancing, backups, and failure handling multiply across shards. And it pushes complexity into the application, which must route to the right shard. Because of all this, I treat sharding as a last resort for write scale, analyze the shard key rigorously, prefer alternatives where they fit (a purpose-built horizontally scalable store like Cosmos DB, or a CQRS read model for read scale), and if I must shard, I do it incrementally with a well-justified key. In an interview I make the reasoning explicit: confirm the bottleneck is really write scale, exhaust simpler rungs first, and only then shard with a defensible key - which shows I understand both the technique and its serious costs rather than reaching for it reflexively.
3.7 Banking Enterprise Scenario
A bank’s platform serves millions of customers with flat tail latency by assembling the toolkit: stateless autoscaled services behind load balancers with session state in Redis; a CDN and distributed cache serving most reads so the origin is shielded; a strongly consistent transaction core with read replicas and a CQRS read model for balances and statements; async queues for notifications and projections off the request path; and rate limiting, timeouts, and circuit breakers protecting the tail. Each mechanism is present because the measured scale justifies it, and each trade-off - cache staleness, read-model eventual consistency - is deliberate.
Chapter Revision Notes
- Scale by removing shared bottlenecks and keeping work off the critical path.
- Stateless horizontal scaling is the foundation; state moves to Redis or the client.
- Caching (CDN, Redis, app) is highest-leverage - design invalidation and stampede protection.
- Scale the DB up a ladder: optimize, replicate, cache, shard, CQRS - each on measured need.
- Offload non-critical work to async queues to keep the synchronous path fast.