Design a Distributed Cache (Redis)
medium 45 minBuild a service like Redis: many machines that together behave as one fast key-value store in memory.
Where it shows up
The same pattern appears across everyday software.
Sessions
A signed-in user's session is read on each request and expires after 30 quiet minutes. A lost session costs a sign-in, so decide whether that is acceptable.
Product pages
Details and price lists are read far more often than they change. A short TTL limits how long an old price shows; the checkout reads the database.
Leaderboards
A sorted set keeps players by score. Reading the top ten or one player's rank takes logarithmic time.
Rate limits
An atomic increment with an expiry counts requests per client. Losing a counter lets a few extra requests through, which is usually fine.
Job queues and messages
Lists and publish/subscribe are handy for light work. A crash can lose items, so payments go through a durable queue instead.
Facebook's Memcached paper
The published paper describes look-aside caching at billions of requests a second, with leases that limit stampedes and stale fills.