Tech Terms Explained Open in the app →

Caching

Architecture · Beginner · 4 min read

What is it?

Caching is storing a copy of expensive-to-get data somewhere fast so future requests can reuse it instead of recomputing or refetching.

Explain like I'm 5

Caching is like writing a friend's phone number on a sticky note so you don't have to look it up in the big directory every single time.

Why was it created?

Recomputing results or hitting a slow database repeatedly is wasteful. Caching was adopted to make systems faster and cheaper by reusing recent results.

Where is it used?

  • Browser and CDN caches
  • Database query results
  • API responses
  • Computed or rendered pages

Why should developers care?

Caching appears at every layer of software — browsers, CDNs, databases, APIs. It's one of the highest-impact performance techniques.

How does it work?

When data is requested, the system first checks the cache. A 'hit' returns the stored copy instantly; a 'miss' fetches the real data, returns it, and stores it for next time, often with an expiry.

Real-world example

A product page caches its rendered HTML for 60 seconds, so a spike of visitors is served from the cache instead of hammering the database.

Common use cases

  • Speeding up repeated reads
  • Reducing database and API load
  • Serving static content fast
  • Storing computed results

Advantages

  • Faster responses
  • Lower load on backends
  • Cheaper at scale
  • Smooths out traffic spikes

Disadvantages

  • Risk of serving stale data
  • Cache invalidation is hard
  • Adds a layer to reason about

When should you use it?

When the same data is read often and a slightly-delayed copy is acceptable.

When should you avoid it?

For data that must always be perfectly fresh and changes constantly.

Alternatives

Reading directly from the source every timePrecomputing and storing results

Related terms

RedisCDNAmazon ElastiCacheHorizontal Scaling

Interview questions

Beginner

  • What is a cache hit and a cache miss?
  • Why use caching?

Intermediate

  • What is a TTL?
  • What is cache invalidation and why is it hard?

Senior

  • What caching strategy would you use for write-heavy data?
  • How do you prevent a cache stampede?

Common misconceptions

  • "Caching always makes things faster" — a poor cache can serve stale or wrong data and add complexity.
  • "Cache everything" — frequently-changing or rarely-reused data may not be worth caching.

Fun facts

  • A famous quip: the two hard things in computing are naming things, cache invalidation, and off-by-one errors.
  • Caches exist at nearly every layer, from CPU to browser.

Timeline

  • 1960s — Caching concepts emerge in early computer hardware

Learning resources

Quick summary

Caching stores reusable copies of expensive data in fast storage to speed up reads and cut load on backends.

Cheat sheet

  • Store results for reuse
  • Hit = fast, miss = fetch + store
  • Use TTLs to expire data
  • Invalidation is the hard part

If you remember only one thing

Caching reuses recent results to avoid repeating slow work — but stale data is the price.