Skip to content

Chapter 2 of 7

Caching & Content Delivery

Caching accelerates data access by storing frequently used information closer to where it is needed. Redis (Remote Dictionary Server) is a popular open-source, in-memory key-value data store that delivers sub-millisecond latency and supports rich data structures including strings, hashes, lists, sets, sorted sets, and streams. Redis offers persistence options through RDB snapshots and the Append Only File (AOF), built-in replication, Lua scripting, pub/sub messaging, and a cluster mode for horizontal scaling.

Memcached is another distributed in-memory caching system, but it is designed for simplicity and raw speed. Compared to Redis, Memcached supports only simple key-value strings, has no persistence, is multi-threaded (versus Redis's traditionally single-threaded model), and lacks built-in replication. Memcached shines for simple caching workloads, while Redis is better suited to complex use cases that benefit from diverse data types and durability.

At the edge of the network, content delivery networks (CDNs) cache static and dynamic content on geographically distributed edge servers. When a user requests content, it is routed to the nearest edge server; if cached, it is served immediately with low latency, and if not cached, it is fetched from the origin, stored, then delivered. CDNs reduce latency, lower origin server load, and provide DDoS protection. CloudFlare, AWS CloudFront, and Akamai are prominent examples.

Keeping caches fresh requires deliberate invalidation strategies. Time-to-live (TTL) expiration is the simplest approach. Event-based invalidation triggers updates on write events, while write-through caching writes simultaneously to both cache and database, and write-behind (write-back) caching writes to the cache first and updates the database asynchronously in batches. Manual purges explicitly delete specific cache keys. The cache-aside (lazy-loading) pattern places the application in charge of the cache: on a read miss, the application queries the database and populates the cache, and on writes it invalidates the cache entry. Read-through caching shifts this responsibility to the cache itself, which loads missing data transparently. Each approach balances latency, consistency, and complexity in different ways.

All chapters
  1. 1Scaling Strategies & Load Balancing
  2. 2Caching & Content Delivery
  3. 3Database Design & Distribution
  4. 4Microservices & Service Communication
  5. 5Rate Limiting & Real-Time Communication
  6. 6Messaging, Events & Streaming
  7. 7Distributed Systems: Consistency, Transactions & Resilience

Drill it

Reading is not remembering. These come from the System Design deck:

Q

What is horizontal scaling?

Horizontal scaling (or scaling out) means adding more machines to your resource pool to handle increased load. For example, going from 1 server to 10 servers be...

Q

What is vertical scaling?

Vertical scaling (or scaling up) means adding more power (CPU, RAM, disk) to an existing machine.Advantages:Simpler architecture — no distributed coordination n...

Q

What is a load balancer?

A load balancer distributes incoming network traffic across multiple backend servers to ensure no single server is overwhelmed.It sits between clients and serve...

Q

What are common load balancing algorithms?

Common algorithms:Round Robin — requests are distributed sequentially across serversWeighted Round Robin — servers with higher capacity get more requestsLeast C...