Caching

Understanding caching in system design and when to use it.

Caching

Caching is simply about not doing the same expensive work twice. When data is requested often, it makes sense to store it closer to the consumer instead of repeatedly querying the original source. Done right, caching reduces latency, protects databases from overload, and makes systems feel fast and responsive.

In practice, caching is never a single decision. It’s a mix of strategies (how data flows) and layers (where data lives).


Caching strategies

Refresh-ahead is a proactive strategy. Instead of waiting for cached data to expire and cause a cache miss, the system refreshes popular entries before they expire.

This works well when access patterns are predictable. Frequently requested data stays warm in the cache, and users rarely experience slow reads.

Note

Refresh-ahead is most effective when traffic patterns are stable and easy to predict.

Disadvantages

  • Wrong predictions waste resources.
  • Refreshing unused data can hurt overall performance.
Loading image...

Types of caching

Client-side caching stores data directly on the user’s device. Web browsers are the most common example, caching pages and static assets locally.

Applications can also cache API responses or computed data on the client.

Pros

  • Reduced server load
  • Faster load times
  • Less network traffic

Cons

  • Risk of stale data
  • Uses client storage