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.