Volume 7 · Chapter 6 — Microservices and System Design
Scalability, Statelessness, and Caching
6.1 Introduction
Designing for scale is a core part of system design, and it rests on a few principles that recur throughout this series: statelessness, horizontal scaling, caching, and asynchronous processing. These are what let a system grow to handle more load by adding capacity rather than hitting a ceiling. This chapter pulls these scalability principles together in the system-design context, because “how would you scale this?” is one of the most common design-interview questions and the answer draws on everything built so far.
6.2 Statelessness and Horizontal Scaling
The foundation of scalability is stateless services combined with horizontal scaling. A stateless service holds no client-specific state locally between requests - any instance can handle any request - so you scale simply by adding more instances behind a load balancer, and each new instance immediately adds capacity. This is horizontal scaling (scale out by adding instances), which scales far better than vertical scaling (making a single instance bigger), because vertical scaling hits a hard ceiling and a single point of failure while horizontal scaling grows almost without limit and is inherently more resilient. For statelessness to work, state must live in shared external stores - session data in a cache or database, files in object storage - not on the instance. Stateless plus horizontal scaling is the pattern behind Auto Scaling groups, containers, and serverless alike.
flowchart TB LB[Load Balancer] --> I1[Stateless instance] LB --> I2[Stateless instance] LB --> I3[Stateless instance +N as load grows] I1 & I2 & I3 --> Shared[(Shared state:\ncache, database, object storage)] Note[Any instance handles any request\nadd instances to scale out] -.-> LB
6.3 Caching to Scale Reads
Databases are often the scaling bottleneck, so caching frequently-read data in memory is one of the most effective ways to scale. Serving hot reads from a cache reduces latency and dramatically offloads the database, letting the system handle far more read traffic without scaling the database as hard. Read replicas similarly scale reads by offloading them from the primary. As covered in the data volume, the discipline is to cache hot, stable, staleness-tolerant data while keeping correctness-critical reads on the source of truth. In a system-design answer, “add a cache in front of the database for hot reads” and “use read replicas to scale reads” are standard, high-impact moves for read-heavy workloads - which most are.
6.4 Asynchronous Processing to Scale Writes and Smooth Load
Not everything needs to happen synchronously in the request path, and moving work out of it is a key scaling technique. Offloading non-urgent work to asynchronous processing - putting a message on a queue for a worker to handle - keeps the user-facing request fast and lets the heavy work happen in the background, scaled independently. Queues also smooth load: a burst of requests is buffered and processed at a sustainable rate rather than overwhelming downstream systems, and you scale the number of workers to the backlog. This is how you handle spikes and heavy processing without over-provisioning the synchronous path - do the minimum synchronously to respond to the user, and push the rest to asynchronous workers that scale independently and absorb bursts.
6.5 Scaling the Data Tier
The data tier is usually the hardest to scale and often the real constraint. The techniques: read replicas and caching to scale reads; choosing a horizontally-scalable store (like DynamoDB) for workloads that need massive scale with simple access; and, for very large relational data, partitioning or sharding to spread it across nodes. The purpose-built-database principle applies - put each workload on a store that scales the way it needs. In a design, recognizing that the database is typically the bottleneck, and addressing it with caching, read replicas, the right store choice, and asynchronous writes, is exactly the depth interviewers look for, because scaling stateless compute is easy while scaling data is where the real thought is required.
6.6 Banking Production Scenario
A bank’s services are stateless behind load balancers in Auto Scaling groups, so they scale out by adding instances as load rises - any instance handles any request, with session state in a cache and data in shared stores. Read-heavy paths (balance and statement lookups) are served through an ElastiCache layer and read replicas, offloading the database so it handles the write load while reads scale cheaply. Placing a payment does the minimum synchronously and pushes fraud scoring, notifications, and ledger propagation to asynchronous queues whose workers scale to the backlog and absorb payday bursts. The authoritative ledger stays on Aurora for ACID, while high-scale simple-access data uses DynamoDB. The system scales by adding stateless compute, caching and replicating reads, and processing asynchronously - never by hitting a single vertical ceiling.
6.7 Troubleshooting: Scaling Bottlenecks
Scaling problems have identifiable bottlenecks. If adding instances doesn’t increase capacity, the service isn’t truly stateless (local state ties requests to instances) - externalize state. If the database is saturated while compute is fine, the bottleneck is the data tier - add caching and read replicas, offload writes asynchronously, or choose a more scalable store. If spikes overwhelm the system, synchronous processing in the request path is the issue - move heavy or non-urgent work to queues that buffer and scale workers. If you’re scaling vertically and hitting a ceiling, switch to horizontal scaling. If a cache isn’t helping, you may be caching the wrong data or have low hit rates. The diagnostic move is to find which tier is the actual constraint - usually data - and apply the matching technique rather than just adding more instances.
How do you design a system to scale, and why is statelessness so important?
I design for scale using a few core principles - stateless services with horizontal scaling, caching and read replicas for reads, and asynchronous processing to offload and smooth work - with particular attention to the data tier, which is usually the real bottleneck. The foundation is statelessness combined with horizontal scaling. A stateless service holds no client-specific state locally between requests, so any instance can handle any request, which means I can scale simply by adding more instances behind a load balancer, and each new instance immediately adds capacity. This horizontal scaling - scaling out by adding instances - is far superior to vertical scaling, which makes a single instance bigger, because vertical scaling hits a hard ceiling and leaves a single point of failure, whereas horizontal scaling grows almost without limit and is inherently more resilient since losing one instance just means the others handle the load. Statelessness is what makes horizontal scaling possible, which is why it’s so important: if instances held local session state, requests would be tied to specific instances, you couldn’t freely add or replace instances, and you’d lose both scalability and resilience - so state must live in shared external stores like a cache, database, or object storage, not on the instance. This is the pattern behind Auto Scaling groups, containers, and serverless alike. For reads, since the database is often the bottleneck, I add caching in front of it for hot, stable data and use read replicas to offload reads from the primary - both let the system serve far more read traffic without scaling the database as hard, while keeping correctness-critical reads on the source of truth. For writes and heavy work, I move non-urgent processing out of the synchronous request path into asynchronous queues, which keeps the user-facing request fast, lets the heavy work scale independently in background workers, and smooths load because a queue buffers bursts and workers process at a sustainable rate - so spikes don’t overwhelm the system. And I pay special attention to the data tier because it’s usually the hardest to scale: read replicas and caching for reads, a horizontally-scalable store like DynamoDB where massive scale with simple access is needed, and partitioning or sharding for very large relational data. Scaling stateless compute is easy - add instances - so the real design thought goes into scaling data. So the design is: stateless services scaled horizontally behind a load balancer with state externalized, caching and read replicas to scale reads, asynchronous processing to offload and smooth writes and heavy work, and the right scalable data stores - and statelessness is central because it’s the property that makes horizontal scaling, the whole basis of scaling out, actually work.
Chapter Revision Notes
- Stateless services + horizontal scaling: any instance handles any request, so add instances to scale out (beats vertical scaling’s ceiling).
- State must live in shared external stores (cache, database, object storage), never on the instance.
- Cache hot reads and use read replicas to offload the database - the usual read-scaling moves.
- Move non-urgent/heavy work to asynchronous queues to keep requests fast, scale workers independently, and smooth bursts.
- The data tier is usually the real bottleneck - address it with caching, replicas, scalable stores, and sharding, not just more compute.