Caching, Consistent Hashing and Sharding

Move reads close to users, distribute data safely, and understand cache and database consistency costs.

Three different tools

A request can use cache for speed, consistent hashing for stable placement, and shards for database scaleA request can use cache for speed, consistent hashing for stable placement, and shards for database scale

ToolSolvesRisk
CacheRepeated read latency/loadStale data and stampedes
Consistent hash ringPlacement when nodes changeHot keys; use virtual nodes
ShardingOne DB cannot hold/write everythingCross-shard work and resharding

Cache-aside reads cache then populates it on a miss. Read-through lets the cache load the source; write-through writes cache and source. TTL, invalidation and request coalescing are part of the design.

A hash ring moves only some keys when nodes change. Choose a stable shard key such as tenant or user ID, and remember: cache is never the source of truth.