Hybrid Rendering Topologies (SSG, SSR, ISR & Edge Cache)
Hybrid rendering pairs HTTP Caching Directives with origin regeneration queues. CDNs serve pre-rendered HTML from Edge Cache Keys in under 20 ms; when TTL expires or a Cache-Tag purges, one background worker rebuilds the page while concurrent visitors still receive stale HTML.
ISR & Edge Cache Regeneration
Trace Edge HIT, STALE single-flight rebuild, and Cache-Tag purge propagation.
Visitor hits CDN PoP within 60 s s-maxage window; HTML returns in 15 ms with 0 origin load.
Cache-Control: public, s-maxage=60, stale-while-revalidate=86400- edgeStatus
- HIT
- originHits
- 0
- ttfbMs
- 15
Under the Hood
ISR (Incremental Static Regeneration) combines CDN stale-while-revalidate headers with a distributed single-flight lock at the origin.
- Edge Hit (
s-maxage): Whileage < s-maxage, the CDN PoP returns cached HTML directly without touching the origin server. - Stale Window & Single-Flight Lock: Once
s-maxageexpires within thestale-while-revalidatewindow, the edge serves the stale response immediately and sends one asynchronous revalidation request to the origin; a distributed lock prevents 500 concurrent users from triggering 500 rebuilds. - On-Demand Tag Purge: CMS webhooks call a purge API with
Surrogate-Key: product-42, evicting all dependent HTML and JSON cache keys globally in ~150 ms.
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Cache-Control: public, s-maxage=60, stale-while-revalidate=86400
Cache-Tag: product-42, category-shoesProblem Genealogy
- 2018 (Monolithic SSG): Rebuilding 50,000 product pages on every typo fix took 25–45 minutes of CI compute.
- 2020 (Time-Based ISR): Moved builds to on-demand runtime queues keyed by
revalidate: 60, capping build times to changed routes only. - 2023 (Tag-Based Edge Invalidation): Replaced blind TTL guessing with
Cache-Tag/revalidateTag()webhooks, delivering instant consistency without sacrificing CDN hit ratios.
Production Pitfalls
- Cache Poisoning via Personalized SSR: Rendering
Set-Cookieor user-specific headers inside ans-maxageroute either leaks private data across users or forces the CDN to bypass caching entirely. - Missing
Varyon Locale or Device: Caching/pricingat the edge without keying onAccept-Languageor currency cookies serves EUR prices to USD visitors.
- When not to use ISR or edge HTML caching: Never cache per-user authenticated dashboards, live order-tracking pages, or CSRF-token forms at a shared CDN PoP; use dynamic SSR or client-fetched personalized islands over a static shell.
Connections & Logical Next Steps
Edge caches store rendered HTML and RSC payloads keyed by URL, Vary headers, and surrogate cache tags.
ISR relies on s-maxage and stale-while-revalidate directives to serve cached HTML during background regeneration.