Buildfest Learn System DesignRead and experiment freely · Chapter activities stay in this tab

LESSON 14 • ESSENTIAL

Scaling and cachingGrow capacity. Reuse results.
Understand the shared limits.

Scaling and caching. Learn the concepts, explore a model and defend your 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
  1. CONCEPTVertical scalingMore resources in one machine
  2. CONCEPTHorizontal scalingMore application instances
  3. 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
  1. STEP 11. Look up keyNo cached value found
  2. STEP 22. Read databaseFetch authoritative data
  3. 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
ToolHelps withDoes not guarantee
More app instancesSuitable shared request loadUnlimited database throughput
Load balancerEligible destination selectionDurable session state
CacheReusable readsFresh or authorized responses
CDNSuitable edge deliveryCorrect 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.