← Lessons

quiz vs the machine

Gold1420

Networking

Surrogate Keys And Targeted Purging

Tagging cached objects so related content can be invalidated together.

5 min read · core · beat Gold to climb

The Purge Problem

When content changes, stale cached copies must be removed. Purging by URL is precise but tedious when one change affects many pages. Surrogate keys solve this with tags.

Tagging Objects

A surrogate key is a label attached to a cached response, sent by origin in a header.

  • A product page might carry the key product 42.
  • A category listing might carry category shoes.
  • One response can hold several keys at once.

The same key can be attached to many objects across the cache.

Purging By Tag

To invalidate everything related to a change, you purge a key rather than a URL.

  • Purge product 42 to clear the product page and every listing that referenced it.
  • The CDN finds all objects bearing that tag and marks them stale.
  • One call invalidates a logical group, regardless of how many URLs it spans.

Why It Scales

  • Decoupled: publishers think in entities, not URLs.
  • Fast: a single purge fans out across the network.
  • Safe: only tagged objects clear, so unrelated content stays cached.

The cost is bookkeeping. The CDN must maintain a reverse index from each key to the objects that carry it.

Key idea

Surrogate keys tag cached objects with logical labels so a single purge by tag invalidates every related response at once, instead of listing each URL by hand.

Check yourself

Answer to earn rating on the learn ladder.

1. What is a surrogate key?

2. Why purge by surrogate key instead of by URL?

3. What bookkeeping does tag based purging require?