Scaling and cachingGrow capacity. Reuse results. Understand the shared limits.
Scaling and caching. Learn the concepts, explore a model and defend your design.
14SYSTEM DESIGN
DEFINITION
Scaling changes available processing resources; caching reuses suitable results so less work must be repeated. Both improve selected workloads only when shared state, freshness and downstream limits remain correct.
Two different ways to grow
CONCEPTVertical scalingMore resources in one machine
CONCEPTShared constraintA bottleneck can remain in storage
Adding application servers helps only when the limiting work can be distributed.
CONCEPT 1
Scale reads without losing correctness
Bigger or more servers
Vertical scaling gives a machine more resources. Horizontal scaling adds instances and shares work. A load balancer selects eligible instances; readiness checks help avoid unusable ones. Keep shared durable state outside one app instance's private memory. Adding servers does not remove a common database or provider limit.
Use headroom after failure
Three servers at an assumed 200 requests per second provide 600 per second ideally. At demand 500, losing one leaves capacity 400, so 100 per second exceeds capacity. Four total servers leave 600 after one failure. Real queues, latency, detection delay and database constraints are excluded from this simple model. Autoscaling also takes time and does not guarantee every burst will be absorbed.
Caches and CDNs
A cache reuses a result; a hit finds it and a miss needs another path. In cache-aside, read the cache, fall back to the source, then fill. Decide acceptable staleness, keys, invalidation and failure behavior. TTL is an expiry policy; eviction manages memory. A CDN can deliver suitable content nearer users. Do not let a shared cache serve one user's private response to another.
Cache-aside on a miss
STEP 11. Look up keyNo cached value found
STEP 22. Read databaseFetch authoritative data
STEP 33. Fill cacheReturn value with bounded TTL
A hit skips the database read. A miss includes both the lookup and retrieval work.
Key learning points
Find the bottleneck before adding instances.
Calculate failure headroom.
Define cache authority, freshness and cold-start behavior.
Compare the important ideas
Scaling and caching: concepts and trade-offs
Tool
Helps with
Does not guarantee
More app instances
Suitable shared request load
Unlimited database throughput
Load balancer
Eligible destination selection
Durable session state
Cache
Reusable reads
Fresh or authorized responses
CDN
Suitable edge delivery
Correct private-page cache policy
WORKED EXAMPLE
Combine capacity and reuse
A fleet of three 200-requests/s servers has 600 ideal capacity. Losing one leaves 400, so offered load of 500 exceeds capacity by 100. A cache may reduce a shared database's repeated reads, but cannot replace correct authoritative handling for stock or permissions.
Further reading
Original teaching explanations by Buildfest Learn. Check these primary references for the underlying concepts and implementation details.
Fail one instance. Find a fleet size that can still serve the offered demand in this model.
12 healthy servers
2400 requests/s capacity
3100 requests/s excess
Offered demand exceeds modeled capacity.
Healthy instances x per-instance capacity gives the ideal fleet limit. Retain room for failures and identify shared dependencies before adding servers.
Chapter review: two questions
Attempt both questions before opening the model answers.
Question 1
At demand 500 requests/s, three servers each handle 200/s. Calculate capacity and excess traffic after one fails.
Reveal model answer
Two healthy servers provide 400/s; offered traffic exceeds capacity by 100/s. Four initial servers would leave an ideal 600/s after one failure, subject to shared bottlenecks.
Question 2
A cache receives 1,000 reads/s with an assumed 80 percent hit rate. Estimate source reads and explain the danger of a cold cache.
Reveal model answer
About 200 source reads/s before other work. A cold cache may send nearly all offered reads to the source, so use a bounded recovery plan and measure source behavior rather than assuming the steady-state ratio.
Answers stay in this tab. Download before leaving. This practice is not graded or saved to your account.