← Lessons

quiz vs the machine

Gold1380

System Design

Cache Invalidation at the Edge

Getting stale content out of edge caches quickly and safely.

5 min read · core · beat Gold to climb

The Hard Problem

Caching content is easy; removing it on time is hard. When the origin changes a file, every edge holding an old copy is now stale. Invalidation is how you force those copies to refresh.

Common Techniques

  • TTL expiry lets each cached object live for a set time, then refetch. Simple but content can be stale until it expires.
  • Purge explicitly tells edges to drop an object now. Fast but every edge must be reached.
  • Versioned URLs add a hash or version to the path so a new file has a new name and old caches never collide.
  • Cache tags group related objects so one purge clears a whole set, like every page using a product.

Trade Offs

Short TTLs keep content fresh but raise origin load. Versioned URLs avoid purges entirely but require build tooling. Purges are immediate but propagation across thousands of nodes takes seconds.

Key idea

Edge invalidation balances freshness against origin load using TTL expiry, explicit purges, and versioned URLs, with versioning sidestepping purge propagation entirely.

Check yourself

Answer to earn rating on the learn ladder.

1. Why do versioned URLs avoid the need to purge caches?

2. What is a drawback of using very short TTLs?

3. What do cache tags let you do?