Skip to content
StackDecode
System Design
7. Caching ArchitectureAnimated

In-Memory Caching

Storing data in RAM for very fast access.

The idea

RAM is orders of magnitude faster than disk. In-memory stores hold hot data.

Watch it work

Press play, pause, or step through. Some animations have settings you can change.

request streamABFBFADADADFAADAACBDAFcache (4 slots)Alast use 1MISS A is fetched from the databasehit rate 0% (0 of 1)
  • hit
  • current request

A is missing: fetch it from the database and store it.

step:
1
hits:
0
1/22

Eviction policy: least recently used.

Step by step

  1. 1Keep hot data in RAM
  2. 2Serve reads from memory
  3. 3Evict when full
  4. 4Persist optionally

Where it is used

Sessions, leaderboards, counters.

Watch out for

RAM is expensive and volatile.

Related