Cloudflare Proxy DNS updates and origin transition latency
0 reputation · 18 Aug 2021, 18:39 UTC
0 reputation · 18 Aug 2021, 18:39 UTC
A small application migration requires shifting traffic from an existing origin to a new infrastructure without incurring downtime. The goal is to utilize Cloudflare's proxy (orange-clouded) DNS records to mask the origin change from the end user.
While the proxy is active, the transition relies on the interaction between DNS record updates and the edge cache. There is uncertainty regarding the propagation delay for origin changes when CNAME flattening is applied to the root domain, specifically concerning how cached content at the edge behaves during the exact moment of the record update.
cf-cache-status header when the origin is switched but the cache has not been explicitly purged?35275 reputation · 19 Aug 2021, 05:52 UTC
cf-cache-status header reflects whether the response was served from the edge cache (HIT, REVALIDATED) or fetched from the origin (MISS, DYNAMIC). It does not change simply because the origin IP or CNAME target has been updated.cf-cache-status will remain HIT (or REVALIDATED if the cache is stale but revalidated). The origin change is invisible until the cache expires or is purged.curl -I https://example.com/resource and look at cf-cache-status. Expect HIT until the cache expires, then MISS followed by DYNAMIC (or MISS if the request is not cacheable).What is the current effective edge‑cache TTL (or Cache‑Control max‑age) for the objects you are migrating? Knowing this tells you how long the old origin may still be served from cache and whether a manual purge is required to meet your downtime‑free goal.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 19 Aug 2021, 00:59 UTC
One detail worth adding to the otherwise solid summary: the edge doesn't just re-resolve per request. Cloudflare maintains keep-alive connection pools to origins, and those pooled connections can keep serving new requests to the old origin IP for the pool's lifetime even after the DNS record has been updated. So "new requests go to the new origin almost immediately" is true on average, but not guaranteed per-request — you can see a brief mix of old and new origin traffic.
Practical implications:
cf-ray alongside origin-side access logs; the origin logs are the ground truth for when traffic actually stops arriving, since cf-cache-status alone won't tell you which origin served a MISS.