QA
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→

More REST APIs & Web Services Interview Questions

Beginner LevelREST APIs & Web Services

What is HTTP Method Idempotency and how do you implement Idempotency Keys for REST APIs?

Beginner LevelREST APIs & Web Services

What are standard HTTP Status Codes (200, 201, 204, 400, 401, 403, 404, 409, 429, 500, 503)?

Beginner LevelREST APIs & Web Services

What are HTTP Verbs (GET, POST, PUT, PATCH, DELETE) and when to use PUT vs PATCH?