System Design Lab / Simulation

Simulate a tiny LRU cache

Send a request sequence through a least-recently-used cache and compare hits, misses and memory limits.

You will learn to

  • Explain eviction
  • Calculate a hit rate
  • Identify the limits of a cache model

Before you start

Arrays and key-value lookup

Trace the path

A request reaches the cache first. On a hit, return its value and mark the key most recently used. On a miss, fetch from the simulated origin, insert the value and evict the least recently used key if capacity is exceeded. The diagram is an original representation of this flow.

A model is not a benchmark

Objects here have equal size and never expire. The latency estimate uses values you choose, not measured network performance. Real systems need invalidation, TTLs, synchronization and memory accounting. A high hit rate does not prove correctness: stale data can be fast and wrong.

Compare workloads

Try A B A C A B with capacities two and three. Compare a hot repeated key with unique keys. Ask whether caching helps with no reuse and which personalized responses must never be shared.

Try it yourself

Enable JavaScript for this interactive activity. You can read all lesson explanations above without it.

Continue exploring