Professional Cloud Network Engineer
Cache invalidation in Cloud CDN involves understanding how content moves between the origin server and edge points of presence (PoPs), with the primary goal of ensuring users receive current content while minimizing unnecessary origin requests that slow response times and increase costs. When a client requests content through Cloud CDN, the system first checks whether the requested resource exists in the cache at the edge location serving the request. A cache miss occurs when the edge location does not have the content, requiring Cloud CDN to fetch the entire response from the origin server—this process is called cache fill. In test scenarios, a first request through the load balancer resulted in a cache miss that took 844 ms to complete, while a subsequent request to the same edge location returned a cached response in just 18 ms.
The geographic distribution of edge locations means that a cache hit is not guaranteed on the first request after content is cached, because the request might be routed to a different PoP that does not yet have the content stored. This is why multiple requests from the same client may be necessary before experiencing the faster cached response. Cloud CDN logs, which are associated with the external Application Load Balancer that backends are attached to, allow operators to verify whether individual requests resulted in cache hits or misses, providing visibility into cache effectiveness across the global network.
When Cloud CDN attempts to fill its cache from the origin, failures can occur due to overloaded servers, network issues, or temporary unavailability. Media CDN implements retry logic that includes configurable retry conditions such as connection failures, HTTP 5xx responses, and 404 Not Found errors. The service retries the primary origin a maximum of three times before attempting to use a configured failover origin, with each retry and failover event increasing cache fill latency because the system must wait through multiple attempt cycles before delivering content or returning an error.
The retry configuration allows operators to specify which conditions trigger retries using the retryConditions field, with options including CONNECT_FAILURE, HTTP_5xx, and NOT_FOUND. The maxAttempts parameter controls how many attempts are made against a single origin before failover occurs, and a global maxAttemptsTimeout sets a deadline for all retry and failover operations combined. These mechanisms ensure that cache fill continues through origin issues but also introduce latency tradeoffs that must be considered when designing cache invalidation strategies.
Cloud CDN can be configured to follow HTTP redirects returned by origins during the cache fill process, rather than returning the redirect response directly to the client. When enabled, Media CDN retrieves content from the redirect location before caching and returning the final response, following redirects across domains. The redirectConditions setting specifies which HTTP status codes cause the CDN to follow a redirect, including MOVED_PERMANENTLY (301), FOUND (302), SEE_OTHER (303), TEMPORARY_REDIRECT (307), and PERMANENT_REDIRECT (308).
This capability is particularly useful when origins redirect requests to different endpoints for load balancing or geographic optimization. However, configuring redirects from untrusted or attacker-controlled origins can expose the CDN to open redirect vulnerabilities, so origin redirection should only be enabled for origins that the operator trusts and controls. Each redirect in a chain is followed, with Media CDN making a single redirect per origin attempt before evaluating retry or failover conditions or returning the final response.
When content changes at the origin and cannot wait for natural expiration, operators can invalidate cached content through Cloud CDN's configuration mechanisms. The approach to invalidation depends on whether the change is planned or emergency-related, and whether the content is static or dynamically generated. For planned updates, using versioned URLs or cache keys allows new content to be served without requiring explicit invalidation, while emergency changes may require immediate invalidation to remove outdated content from all edge locations simultaneously. The configuration examples in the documentation show how origin settings interact with caching behavior, including origin-specific host rewrites and header modifications that can affect how content is cached. The originOverrideAction configuration allows operators to set per-origin headers, such as static Authorization headers, which are added during origin requests and can influence cache key generation and content storage decisions.
Cache invalidation for Cloud CDN is the process of forcing cached content at Google's edge points of presence (PoPs) to be refreshed before its natural time-to-live (TTL) expires. An aggressive invalidation strategy forces cached objects to be re-fetched from the origin server as soon as content is updated. When you issue an invalidation request, Cloud CDN marks the specified content as stale across all its edge caches. The next user request for that content triggers a new fetch from the origin, ensuring freshness but increasing load on the backend. This approach is critical for content that must be consistent globally immediately after an update, such as a pricing change on an e-commerce site. However, frequent invalidations for large or popular objects can significantly increase origin server load and associated compute costs, as every edge pop must refetch the content.
A TTL-based strategy relies on the cache expiration time set in the HTTP headers from the origin server. During this period, user requests are served directly from the cache, resulting in very low latency—as fast as 18ms for a cache hit compared to 844ms for a miss that requires an origin fetch. This method minimizes origin load and egress costs because the origin server is only contacted when the TTL expires. The trade-off is that users may see stale content until the TTL passes. This strategy is best for static or infrequently updated content where immediate consistency is not required, allowing you to optimize for cost and performance.
The choice between aggressive invalidation and TTL expiration involves calculating their effects on three key areas: origin load, egress costs, and latency. Invalidating content immediately ensures freshness but forces a surge of origin fetches, increasing load and egress charges. Letting content expire naturally based on TTL shields the origin and reduces costs but risks serving outdated data. For content with high update frequency, a very short TTL can be a middle ground, but it increases origin load compared to a longer TTL. You must analyze your content update patterns: high-frequency updates may justify the cost of aggressive invalidation for critical data, while static assets should use longer TTLs to maximize cache efficiency and minimize expenses.
Cache invalidation and cache purge mechanisms force edge caching infrastructure to stop serving stale content and retrieve updated assets directly from origin backends. In Cloud CDN and Media CDN, edge points of presence (PoPs) store static and streaming content close to clients to minimize round-trip network latency. Edge caching separates the low-latency delivery of cached responses at network edges from higher-latency origin fetch operations. When a client issues a request for an asset that resides in an edge PoP cache, Cloud CDN fulfills the request directly with minimal latency, dropping response times significantly from hundreds of milliseconds down to tens of milliseconds. Conversely, a request for an invalidated or uncached path results in a cache miss, forcing the edge proxy to route traffic back across the network to the origin service or storage bucket. This cache fill step incurs round-trip transit time and origin processing delays, resulting in substantially higher response latency for end users until the edge PoPs are repopulated.
Targeted invalidation clears specific asset URLs or paths, whereas broad flushes remove wide directory patterns or entire cache namespaces across edge locations. Specific URL invalidation limits cache fill operations to individual modified objects, preserving high cache hit ratios for all unrelated assets. In contrast, broad wildcard invalidations or full cache flushes remove wide directory patterns or entire cache namespaces across edge locations, forcing all subsequent user requests across global PoPs to trigger simultaneous cache misses. This sudden surge in cache fill requests transfers high operational load onto origin backends, which can exhaust backend capacity and increase latency across the network.
When invalidated content forces cache fills to origin services, backend failover and retry configurations determine how edge nodes handle connection delays or backend errors. In Media CDN, an EdgeCacheOrigin resource can be configured with primary and failover origins, retry conditions such as connection failures or HTTP 5xx and 404 status codes, and redirect-following rules. If an origin experiences high load or errors during a cache fill, the system attempts retries up to a configured limit, supporting a maximum of four total attempts across all configured origins before returning an HTTP 502 Bad Gateway or 504 Gateway Timeout response. Every retry and failover event adds cumulative delay to the overall cache fill latency, highlighting the need to manage invalidation scope to protect origin stability.
Cache invalidation typically refers to targeted removal of specific URLs or paths, while cache purge often refers to broad flushes that remove entire directories or cache namespaces. Targeted invalidation preserves cache hit ratios for unrelated content, whereas broad purges force all requests to trigger cache fills, significantly increasing origin load.
Use aggressive invalidation for content that must be consistent globally immediately after an update, such as pricing changes or emergency announcements. Use TTL-based expiration for static or infrequently updated content where immediate consistency is not required, optimizing for cost and performance.
Each retry and failover event adds cumulative delay to the overall cache fill latency. Media CDN attempts up to three retries on the primary origin before attempting a failover origin, with a global timeout setting a deadline for all operations combined.
Prepare and test your skills
Prepare and test your skills