Skip to content

Latest commit

 

History

History
33 lines (24 loc) · 1.36 KB

File metadata and controls

33 lines (24 loc) · 1.36 KB

Design a distributed cache (like Redis)

An in-memory key-value cache spread across many nodes, for fast reads and reduced load on the data store.

Requirements

  • Fast get and set by key.
  • Scale beyond one machine's memory.
  • Handle node failures without losing the whole cache.
  • An eviction policy when memory is full.

Key ideas

  • Partitioning: spread keys across nodes with consistent hashing so adding or removing a node moves few keys.
  • Replication: replicate each shard so a node failure does not lose its data (see replication).
  • Eviction: LRU is the common default; also support TTL expiry.
  • Consistency: caches are usually best-effort, so plan invalidation (see caching) and accept brief staleness.

High-level design

flowchart LR
    Client --> Router{Consistent Hashing}
    Router --> N1[(Cache Node 1)]
    Router --> N2[(Cache Node 2)]
    Router --> N3[(Cache Node 3)]
Loading

Go deeper