Overview
Curated: · Written: · Reviewed:
Scalability Fundamentals
In one line
Scalability means meeting a changing workload at a stated latency, error and freshness target. Measure the bottleneck first, then scale or remove the constraint that is actually limiting, and define overload behaviour before traffic arrives.
Key definitions
- Offered load and goodput: what arrives per second, and what completes within its objective. Report both.
- Bottleneck: the first resource to saturate under load. It moves after each fix, so retest.
- Stateless: any eligible instance can serve the next request. The state lives in a cookie, database, cache or durable store.
- Backpressure: a full queue or slow consumer pushes waiting or refusal upstream instead of growing memory.
- Admission control: rejecting work at the edge when it cannot finish inside its deadline.
- Retry budget: a cap on retries as a share of recent requests, so retries cannot multiply an outage.
Formulas and complexity
Amdahl: with serial fraction s, the speedup ceiling is 1/s, and it is never reached in practice.
Adding pool connections does not add work. At 3,000 req/s and 15 ms per query, 45 queries are in flight.
- Numbers to quote: 1/8 of follow-up requests hit the owning instance under round robin with 8 instances (7 of 8 miss). A 10% retry budget on 2,000 rps over 10 s allows 2,000 retries. Overlapping outages: 432 + 432 + 432 minutes with a 400-minute shared overlap gives 896 minutes, or 97.93% in a 43,200-minute window, not 0.99^3.
How it works
- Clients hit a load balancer that spreads work. It adds no backend capacity and assumes roughly equal work per request.
- Stateless API instances share a connection pool. Pool size, not instance count, often sets the ceiling.
- Autoscaling is delayed feedback: signal, decide, boot, warm. Headroom and admission control cover that gap.
- Liveness checks only the process. Readiness checks what the instance needs to serve. A shared-dependency failure must not remove the whole fleet.
When to use and when not to
| Choice | Use when | Avoid when |
|---|---|---|
| Vertical scaling | Quick relief; state is hard to partition | Node ceiling is near; no failure domain left |
| Horizontal scaling | Work partitions; shared dependencies have headroom | The shared writer or pool is the limit |
| Sticky sessions | Local state is costly to externalize | Failover must be seamless; hot keys |
| Scheduled scaling | Predictable peaks | Unpredictable spikes |
| Reactive autoscaling | Gradual, measurable demand | Ramps faster than boot and warm-up time |
| Load shedding | Offered load exceeds useful capacity | You can still add capacity cheaply |
Traps interviewers probe
- Adding application nodes when a shared pool or primary is saturated. Fix: read per-tier utilization and wait time, scale the saturated tier, and count connections against the database limit.
- Session or cart state held in process memory. Fix: move it to a shared store, or use sticky routing and state the failover loss in advance.
- Health checks that call a shared dependency. Fix: liveness checks the process only. A 2 s interval with an unhealthy threshold of 3 removes every instance within about 4 s when the database fails.
- Multiplying availability when components share failures or are not all mandatory. Fix: take the union of downtime and recompute.
- Unbounded queues and unlimited retries. Fix: bounded queues, end-to-end deadlines, a retry budget, and 503 with Retry-After when overloaded.
Interview tips
Open with the workload and SLO, then the mandatory dependency path, then the bottleneck you measured. Do not start with the component you would scale.
Expected follow-ups:
- What did you measure, and what would falsify the design?
- The database saturates after you add nodes. What now?
- How does autoscaling handle a 10x spike?
- What happens when a zone is lost at peak?
- What is the retry policy, and where do retries happen?
30-second outline: The SLO is p99 200 ms at 1,000 rps. The per-tier data shows the connection pool saturated while application CPU is low. I would raise pool capacity and check connection hold time, not add nodes, because more nodes add waiters to the same pool. I would keep offered load and goodput separate, bound the queue, set deadlines, and cap retries with a budget. I would confirm the fix with a repeated step load test that watches pool wait, database CPU and goodput.
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.