Chaturmind
LearnDSASystem DesignDevOpsEngineering GrowthBlog
Start learning
Chaturmind

Structured learning paths for engineers who want to go deep. Written by practitioners.

Learn

  • Java
  • DSA
  • System Design
  • Spring Boot
  • AI / ML
  • DevOps
  • Engineering Growth

Company

  • Blog
  • Contact

Legal

  • Privacy Policy
  • Terms of Service

ยฉ 2026 Chaturmind. All rights reserved.

Built for engineers who want to go deep.


โ† System Design Interview Playbook

Interview Framework

  • The 6-Step Design Framework
  • HLD Fundamentals Refresher
  • Requirement Gathering Practice
  • Domain Decomposition
  • API Contract Design
  • Data Ownership Model
  • Failure Scenario Walkthroughs
  • Architecture Diagramming
  • Back-of-Envelope Estimation

10 Case Studies

  • Design a URL Shortener
  • Design Twitter / X
  • Design WhatsApp
  • Design Netflix
  • Design a Rate Limiter
  • Design a Search Autocomplete
  • Design a Distributed Cache
  • Design a Notification Service
  • Design Uber / Ride Sharing
  • Design a Distributed File Storage System
  • Design a Distributed Task Scheduler
  • Design a Message Queue System
  • Design an Authentication System at Scale
  • Design a Distributed Logging & Metrics Pipeline
  • Design a Food Delivery Platform
  • Design a Real-Time Analytics Dashboard
  • Design a Monitoring & Alerting System
  • Design Container Orchestration Basics
  • Design a CI/CD Pipeline System
  • Design Service Mesh Basics
  • Design a Centralized Configuration & Secrets System
  • Design a Batch Processing System
  • Design a Data Warehouse / Analytics Storage Layer
  • Design Global Content Delivery
  • Case studies

    ๐Ÿ—๏ธDesign a URL Shortener
  • ๐Ÿ—๏ธDesign a Rate Limiter
  • ๐Ÿ—๏ธDesign Twitter / X
  • ๐Ÿ—๏ธDesign WhatsApp
  • ๐Ÿ—๏ธDesign Netflix
  • ๐Ÿ—๏ธDesign a Distributed Cache
  • ๐Ÿ—๏ธDesign a Notification Service
  • ๐Ÿ—๏ธDesign a Search Autocomplete System
  • ๐Ÿ—๏ธDesign Uber / Ride Sharing
  • ๐Ÿ—๏ธDesign a Web Crawler
  • ๐Ÿ—๏ธDesign a Payment System
  • ๐Ÿ—๏ธDesign a Distributed Lock Service
  • ๐Ÿ—๏ธDesign a Video Streaming Platform
  • ๐Ÿ—๏ธDesign a Search Engine
  • ๐Ÿ—๏ธDesign E-Commerce Checkout & Inventory at Scale
Chaturmind
โ† System Design Interview Playbook

Interview Framework

  • The 6-Step Design Framework
  • HLD Fundamentals Refresher
  • Requirement Gathering Practice
  • Domain Decomposition
  • API Contract Design
  • Data Ownership Model
  • Failure Scenario Walkthroughs
  • Architecture Diagramming
  • Back-of-Envelope Estimation

10 Case Studies

  • Design a URL Shortener
  • Design Twitter / X
  • Design WhatsApp
  • Design Netflix
  • Design a Rate Limiter
  • Design a Search Autocomplete
  • Design a Distributed Cache
  • Design a Notification Service
  • Design Uber / Ride Sharing
  • Design a Distributed File Storage System
  • Design a Distributed Task Scheduler
  • Design a Message Queue System
  • Design an Authentication System at Scale
  • Design a Distributed Logging & Metrics Pipeline
  • Design a Food Delivery Platform
  • Design a Real-Time Analytics Dashboard
  • Design a Monitoring & Alerting System
  • Design Container Orchestration Basics
  • Design a CI/CD Pipeline System
  • Design Service Mesh Basics
  • Design a Centralized Configuration & Secrets System
  • Design a Batch Processing System
  • Design a Data Warehouse / Analytics Storage Layer
  • Design Global Content Delivery
  • Case studies

    ๐Ÿ—๏ธDesign a URL Shortener
  • ๐Ÿ—๏ธDesign a Rate Limiter
  • ๐Ÿ—๏ธDesign Twitter / X
  • ๐Ÿ—๏ธDesign WhatsApp
  • ๐Ÿ—๏ธDesign Netflix
  • ๐Ÿ—๏ธDesign a Distributed Cache
  • ๐Ÿ—๏ธDesign a Notification Service
  • ๐Ÿ—๏ธDesign a Search Autocomplete System
  • ๐Ÿ—๏ธDesign Uber / Ride Sharing
  • ๐Ÿ—๏ธDesign a Web Crawler
  • ๐Ÿ—๏ธDesign a Payment System
  • ๐Ÿ—๏ธDesign a Distributed Lock Service
  • ๐Ÿ—๏ธDesign a Video Streaming Platform
  • ๐Ÿ—๏ธDesign a Search Engine
  • ๐Ÿ—๏ธDesign E-Commerce Checkout & Inventory at Scale
HomeLearnSystem DesignSystem Design Interview Playbook10 Case Studies
โœ“ FreeAdvancedยท 7 min read

Design a Distributed Cache

How to run a Redis-like distributed cache design in a 45-minute interview: consistent hashing, eviction, replication and failover, stampedes and hot keys.

Published September 21, 2026


Design a Distributed Cache โ€” the 45-minute interview walkthrough

This lesson is the interview version of designing a Redis/Memcached-like system: how to structure the answer and which deep dives to prepare. The full reference design is the case study Design a Distributed Cache in this chapter.

A cache keeps copies of frequently used data in memory so reads don't hit a slower database. A distributed cache spreads that data across many machines, because the working set is bigger than one machine's RAM, or the request rate is higher than one machine can serve. The design has three core problems: which node holds a key, what happens when nodes come and go, and what to evict when memory is full.

Minutes 0โ€“5: clarify requirements

  • Operations: get, set (with TTL), delete. Anything richer (counters, lists, sorted sets)?
  • Size and load: e.g. 10 TB of data, 1 million requests/s, p99 latency under ~1โ€“2 ms within a data centre.
  • Consistency: is serving slightly stale data acceptable? (Almost always yes for a cache, and saying so simplifies the design.)
  • Durability: is losing cache contents on restart acceptable? (Usually yes: the database is the source of truth.)
  • Availability: a cache outage shouldn't take the product down, but a cold cache can overload the database. That's the failure to plan for.

Minutes 5โ€“15: the high-level design

 App servers (cache client library)
      โ”‚  hash(key) โ†’ node      โ† routing happens in the client, no extra hop
      โ–ผ
 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”        each node: in-memory hash table
 โ”‚ Node A  โ”‚  โ”‚ Node B  โ”‚  โ”‚ Node C  โ”‚  ...   + LRU eviction + TTL expiry
 โ”‚ primary โ”‚  โ”‚ primary โ”‚  โ”‚ primary โ”‚
 โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜
      โ–ผ            โ–ผ            โ–ผ
   replica      replica      replica          async replication for failover
      โ–ฒ
 Cluster config service (membership, which node owns which range) โ† clients subscribe to changes

Explain the flow for a read (cache-aside, the most common pattern): the app asks the cache; on a miss it reads the database and writes the value into the cache with a TTL; on a hit it returns immediately.

Minutes 15โ€“35: the deep dives

1. Which node holds a key: consistent hashing

The naive approach, node = hash(key) % N, breaks badly when N changes. Adding one node to 10 remaps about 90% of keys, and suddenly almost every request is a miss, so the database gets flattened.

Consistent hashing places both nodes and keys on a hash ring, and each key belongs to the next node clockwise. Adding or removing a node only moves the keys in that node's arc, roughly 1/N of the keys. Virtual nodes (each physical node appears at 100โ€“200 points on the ring) even out the load and spread a failed node's keys across all survivors, instead of dumping them on one neighbour. Redis Cluster uses a close cousin: 16,384 fixed hash slots assigned to nodes.

2. Eviction: what to drop when memory is full

  • LRU (least recently used): drop what hasn't been read longest. It's implemented with a hash map plus a doubly linked list for O(1) get/put, the classic interview coding problem. Real systems often use approximate LRU (sample a few keys, evict the oldest) to avoid the memory cost of the list.
  • LFU (least frequently used) is better when some keys are consistently hot.
  • TTL expiry removes stale data: lazily when a key is accessed, plus a background sweep so expired but unread keys don't waste memory.

3. Replication and failover

Each primary has one or more replicas, updated asynchronously (a synchronous copy would double write latency). When a primary fails, heartbeats detect it, a replica is promoted, and the cluster config is updated so clients re-route. Be explicit about the trade-off: writes acknowledged by the old primary but not yet replicated are lost on failover. For a cache that's acceptable, and that's exactly why the database stays the source of truth.

4. The failure modes that actually hurt

  • Cache stampede (thundering herd): a hot key expires, and 10,000 requests miss at once and all hit the database. Fixes: request coalescing (only one request recomputes, the others wait for it), a per-key lock, or early refresh before expiry.
  • Hot keys: one celebrity key gets a large share of traffic and overloads its node. Fixes: replicate that key to several nodes, or add a small local in-process cache on app servers for the hottest keys.
  • Cold start after a big outage: a warm-up strategy, or rate-limiting database access while the cache refills.
  • Stale data after writes: on update, delete the cache entry (don't try to update it in place), and keep TTLs short enough that any missed invalidation self-heals.

Minutes 35โ€“45: trade-offs and wrap-up

  • Client-side routing (a smart client knows the ring) saves a network hop, but means updating client libraries. A proxy layer is simpler for clients and costs one hop.
  • Async replication gives low latency with a small risk of losing recent writes on failover. That's acceptable for a cache.
  • Eventual consistency with the database, bounded by TTL and delete-on-write.
  • With more time: multi-region caches, persistence snapshots for faster restarts, memory-efficient encodings for small values.

Common mistakes in interviews

  • Using hash % N and not noticing what happens when a node is added.
  • Treating the cache as the source of truth.
  • Ignoring stampedes and hot keys, the two problems production caches actually struggle with.
  • Proposing synchronous replication without acknowledging the latency cost.

Follow-up questions this topic invites โ€” and their answers

Q: Cache-aside, read-through, write-through or write-behind: which would you use? A: Cache-aside (the app manages the cache) is the most common because it's simple and fails safe: if the cache is down, the app reads the database. Read-through/write-through move that logic into the cache layer. Write-through keeps the cache fresh at the cost of write latency. Write-behind (write to the cache, flush to the database later) is fast but risks losing writes, so it's rarely acceptable for important data.

Q: When you update the database, should you update the cache or delete the entry? A: Delete it. Updating risks writing an older value over a newer one when two updates race. Deleting forces the next read to load the current value. Delete after the database commit, and keep a TTL as a safety net in case a delete is lost.

Q: How do you handle a node that's slow rather than dead? A: Use tight client timeouts and treat a timeout as a miss (fall back to the database), with a circuit breaker so a sick node isn't hammered. Health checks that measure latency, not just liveness, can take it out of rotation. Slow nodes are often more damaging than dead ones because they tie up client threads.

Q: Redis or Memcached? A: Memcached is a simple, multi-threaded key-value cache, excellent for plain get/set of blobs. Redis is single-threaded per shard for commands, but offers rich data structures (lists, sorted sets, streams), persistence, replication and clustering. Choose Memcached for pure, simple caching at high throughput, and Redis when you need its data types or durability features.

Previous

Design a Search Autocomplete

Next

Design a Notification Service

AI Tutor

Lesson: Design a Distributed Cache

Quick actions

AI responses can be inaccurate. Verify critical information.