Intermediate LevelSystem Design & Architecture
How do Cache-Control directives and Surrogate Keys (Cache-Tags) control CDN purging?
β Interview Prompt: Explain `Cache-Control` directives (`public`, `s-maxage`, `stale-while-revalidate`), and `Surrogate-Key` / `Cache-Tag` CDN cache purging.
HTTP response headers govern CDN edge caching behavior:
Directives & Cache-Tags:
β’
's-maxage=3600': Instructs CDN edge proxies to cache the response for 1 hour.
β’
'stale-while-revalidate=60': Serves stale content from CDN cache while fetching a fresh copy asynchronously in the background.
β’
'Surrogate-Key / Cache-Tag': Assigns tag identifiers to cached pages ('Cache-Tag: product-100'), allowing instant targeted CDN cache purging of thousands of pages with a single API call!
Code Implementation Example
http
HTTP/1.1 200 OK
Cache-Control: public, s-maxage=86400, stale-while-revalidate=300
Cache-Tag: category-electronics, brand-sonyπ‘CDN Cache-Control and Cache-Tag HTTP response headers.
π― Interview Key Takeaway
Use Surrogate-Key / Cache-Tag headers to execute instant targeted CDN cache invalidation across related pages.
#System Design#CDN#Cache-Control#Cache-Tag#Intermediate
Back to all System Design & Architecture Questionsβ