Intermediate LevelREST APIs & Web Services
How do CDN Cache Invalidation and Surrogate-Key (Cache-Tags) headers operate?
❓ Interview Prompt: Explain CDN edge caching, `Surrogate-Key` / `Cache-Tag` headers, purge APIs, and instant cache invalidation.
Hard-purging entire CDN caches ('/api/v1/') is slow and degrades origin server performance (Cache Stampede). Using Cache Tags / Surrogate Keys*:
How It Works:
1
Origin server returns response with tag header: 'Surrogate-Key: user_42 product_88'.
2
CDN (Fastly, Cloudflare) stores the response and indexes it under both tags.
3
When user 42 updates profile, server issues an API call to CDN: 'PURGE /tags/user_42'.
4
CDN instantly invalidates ONLY cached responses tagged with 'user_42' across edge nodes globally!
Code Implementation Example
http
HTTP/1.1 200 OK
Cache-Control: public, max-age=31536000
Surrogate-Key: entity_user_42 user_feed
Content-Type: application/json
{ "id": 42, "name": "Alice" }💡Surrogate-Key header enabling tagged CDN edge cache purging.
🎯 Interview Key Takeaway
Use Surrogate-Key headers to tag CDN responses for targeted instant cache invalidation without flushing entire site caches.
#CDN#Surrogate-Key#Cache Invalidation#Intermediate
Back to all REST APIs & Web Services Questions→