ARTICLE - CDN Acceleration

Google Cloud CDN Guide: Backends & Cache Modes

Google Cloud CDN uses Googles global edge network (GFE) to serve content closer to users, speeding up websites and applications. It is not a standalone gateway.

2026-08-06 Google Cloud Documentation

Google Cloud CDN Guide: Backends & Cache Modes

What Is Cloud CDN

Google Cloud CDN uses Google's global edge network (GFE) to serve content closer to users, speeding up websites and applications. It is not a standalone gateway; it works with the external Application Load Balancer: the load balancer provides the frontend IP and port, while Cloud CDN handles caching and delivery. So the prerequisite is a load balancer, then you enable caching on the backend service.

Step 1: Configure a Backend Service

Cloud CDN content can come from several backends:

  • VM instance groups: run web server software, good for mixed dynamic/static workloads.
  • Cloud Storage buckets (backend buckets): ideal for pure static assets, images, and packages.
  • Managed instance groups and NEGs (network endpoint groups), among others.

Tick Enable Cloud CDN on the load balancer backend service to start caching all cacheable content. Pair it with Cloud Armor security policies: edge policies apply to all traffic before the CDN, while backend policies only apply to dynamic origin requests.

Teams that live in the CLI or write infrastructure as code can enable the CDN directly on an existing backend service with gcloud:

gcloud compute backend-services update BACKEND_SERVICE_NAME \
  --global \
  --enable-cdn \
  --cache-mode=CACHE_ALL_STATIC \
  --default-ttl=3600

Here --cache-mode and --default-ttl are the CLI equivalents of the cache mode and default TTL in the console — the flags you reach for almost every day when writing Terraform or deployment scripts.

Step 2: Choose a Cache Mode

The origin uses HTTP response headers (such as Cache-Control) to indicate what can be cached, and you can override behavior with a cache mode in the console:

  • USE_ORIGIN_HEADERS: fully honor origin response headers; flexible but requires correct origin setup.
  • CACHE_ALL_STATIC: cache all static content, ignoring origin headers.
  • FORCE_CACHE_ALL: force caching of everything, including dynamic responses, for known-safe endpoints.

The trade-offs between the three are easier to see side by side:

Cache mode Honors origin headers Typical use Watch out for
USE_ORIGIN_HEADERS Yes Origin Cache-Control already correct A bad origin header silently breaks caching
CACHE_ALL_STATIC Static assets Images, CSS, JS, installers Dynamic endpoints stay uncached
FORCE_CACHE_ALL No Known-safe pages and APIs Sensitive dynamic content may be cached

For a static site that needs quick wins, start with CACHE_ALL_STATIC; only move to FORCE_CACHE_ALL for endpoints you have confirmed are side-effect-free.

You can also set custom cache keys (ignore query parameters, group by header), TTL overrides, and negative caching (short caching of 404s and similar). Key granularity decides the balance between hit ratio and freshness — for example, ignoring the query string while grouping by Accept-Language:

gcloud compute backend-services update BACKEND_SERVICE_NAME \
  --global --enable-cdn \
  --cache-key-policy-include-query-string=false \
  --cache-key-policy-include-http-header=Accept-Language

Requests to the same URL now share the cache, while users of different languages still get their own version. For hit-ratio tuning see CDN cache hit ratio optimization, and for broader strategy see CDN cache strategy.

Step 3: Manage the Cache and Invalidations

  • Cache hit/miss: on a hit, GFE returns cached content directly; on a miss, it fetches from the origin and fills the cache.
  • Invalidation: after updates, invalidate in the console, either by prefix or per URL.
  • Expiration vs eviction: expiration decides when content is "stale," while eviction is driven by cache-space pressure; they are independent, and popular content tends to stay cached longer.

Step 4: Set Up Signed URLs and Signed Cookies

To protect private content, use signed URLs or signed cookies:

  • Signed URLs: append an expiry and signature to the URL, suitable for temporary sharing and download sites.
  • Signed cookies: better when you need to protect a whole site for logged-in users.
  • Both support custom URL prefixes, IP ranges, and start/expiry time constraints, and combine with private Cloud Storage access.

Step 5: Understand Quotas and Pricing

Cloud CDN bills by cache egress, cache fill, and cache lookup; higher hit ratios mean lower cost. Accounts have quotas on backend services, invalidations, and more, which can be raised in the IAM and Quotas page. For cost tuning see CDN cost optimization guide.

A Real Scenario: Speeding Up a Static Product Site

Say your product site lives in a Cloud Storage bucket, roughly 40 MB of assets, with about 60% of visitors in Europe and the US. Before enabling Cloud CDN, users in Tokyo or Frankfurt hit the origin every time — a single region — and hero images often took two to three seconds to render. After enabling it, the edge serves cache hits without going to origin, TTFB typically drops to 100-200 ms, and egress shifts from "full origin fetch" to "edge egress." With a high hit ratio, the bandwidth bill can easily fall by more than half.

The whole payoff depends on the hit ratio. If frequently parameterized URLs fragment your above-the-fold assets, the ratio never rises; see the hit-ratio article above for the fix. One point that is easy to overlook: if origin requests queue at the source, the CDN just concentrates pressure into the cache-miss moment, so cache warming and origin scaling matter just as much.

When to Choose It

Cloud CDN suits teams already on Google Cloud that want load balancing, Cloud Armor, and GKE integrated; GKE clusters can enable Cloud CDN through the Ingress BackendConfig with near-zero extra operations. The downside is that you must first build a load balancer architecture, which feels heavy for a pure static small site. For selection see our CDN provider selection guide.

16IDC Take

Cloud CDN is essentially "caching built into the load balancer": entry, routing, caching, and security (Cloud Armor) live in one Google network, ideal for cloud-native teams. If your site runs on a plain VPS and you only want static acceleration, a standalone CDN is lighter to adopt. More content in the CDN acceleration category.

Reference: Cloud CDN overview https://cloud.google.com/cdn/docs/overview · Cache keys https://cloud.google.com/cdn/docs/caching · Signed URLs https://cloud.google.com/cdn/docs/using-signed-urls
Source: https://cloud.google.com/cdn/docs/overview

Integration & Code Examples

Example 1: Create a CDN-enabled backend service and set the cache mode

#!/usr/bin/env bash
set -euo pipefail

PROJECT_ID="$(gcloud config get-value project)"

# Static-heavy site: cache broadly first, then let TTLs correct it
gcloud compute backend-services create web-backend \
  --project="${PROJECT_ID}" --global --protocol=HTTP \
  --enable-cdn --cache-mode=CACHE_ALL_STATIC \
  --default-ttl=3600 --client-ttl=3600 --max-ttl=86400

# On an existing backend: let origin Cache-Control decide instead
gcloud compute backend-services update web-backend \
  --project="${PROJECT_ID}" --global \
  --cache-mode=USE_ORIGIN_HEADERS

gcloud compute backend-services describe web-backend --global \
  --format='value(cdnPolicy.cacheMode)'

The cache mode decides who is in charge: CACHE_ALL_STATIC lets the CDN judge, USE_ORIGIN_HEADERS hands the decision back to the origin.

Example 2: Invalidate cached objects and sign a URL

#!/usr/bin/env bash
set -euo pipefail

URL_MAP="web-map"

# 1) After a release, invalidate only the changed prefix instead of everything
gcloud compute url-maps invalidate-cdn-cache "${URL_MAP}" \
  --path="/assets/*" --async

# 2) Private content uses signed URLs; the key stays in a file referenced by env
gcloud compute sign-url "https://cdn.example.com/private/report.pdf" \
  --key-name="${SIGN_KEY_NAME:?}" \
  --key-file="${SIGN_KEY_FILE:?}" \
  --expires-in=1h

Invalidation is asynchronous, so verifying immediately can still hit the old object; release and load-test flows need that window.

Three Layers: Cache Mode, TTL and Cache Key

The console options look like this on the command line: --cache-mode decides who has the final say, --default-ttl / --client-ttl / --max-ttl decide how long an object lives, and --cache-key-policy-* decides whether two URLs share one cached copy. Change the wrong layer and the hit ratio drops.

The mode wins: CACHE_ALL_STATIC ignores origin headers and caches static content, USE_ORIGIN_HEADERS hands the decision back to the origin, and FORCE_CACHE_ALL caches dynamic responses too. TTL only shows up when there is no origin header to follow, so it works as a fallback rather than a strategy.

Parameter CLI option Sample value in this article What it decides
Cache mode --cache-mode CACHE_ALL_STATIC / USE_ORIGIN_HEADERS Whether origin headers or platform policy wins
Default TTL --default-ttl 3600 seconds Lifetime when the origin sends no Cache-Control
Client TTL --client-ttl 3600 seconds How long the browser keeps the object
Max TTL --max-ttl 86400 seconds Ceiling when the origin asks for a longer TTL
Query string in key --cache-key-policy-include-query-string false Whether parameterised URLs share one copy
Header in key --cache-key-policy-include-http-header Accept-Language Whether languages are cached separately

The Invalidation Window and Hit-Ratio Readings

Invalidation is asynchronous: after invalidate-cdn-cache you may still read the old object for a short while. The release flow either invalidates before verifying or leaves a window for verification, otherwise a stale cache looks like a failed deploy.

Hit-ratio readings only mean something next to the traffic profile. In the 40 MB static site where about sixty percent of visitors come from Europe and North America, TTFB usually lands at 100-200 ms after enabling CDN, and egress shifts from full origin fetches to edge delivery; break the first-screen assets into high-cardinality parameter URLs and that gain disappears.

If origin requests queue at the origin, CDN merely concentrates pressure on the moment the cache is missed. Warm-up and origin capacity have to move together; edge nodes alone cannot absorb a stampede.

Limitations

  • The downside is that you must first build a load balancer architecture, which feels heavy for a pure static small site.
  • Figures reflect public information at publication; terms, prices and quotas follow the provider's current published terms.
  • This article reflects public information as of 2026-08-06; terms, prices and quotas follow the provider's current published terms.

FAQ

Which layer is required before enabling Cloud CDN?

A global external Application Load Balancer. Cloud CDN is not a standalone gateway: the load balancer supplies the frontend IP and port, and caching is switched on per backend service. A site with only a VPS and no load balancer has to build that layer first.

Which line items make up Cloud CDN billing?

Three line items: cached egress, cache fill traffic and cache lookups. Higher hit ratios cut cache fill and origin egress, lowering the total, while poor TTL and cache-key design scatter the hit rate and raise it. Backend counts and invalidations carry separate quotas, raised through the IAM and quotas page.

Why does a changed cache mode seem to have no effect?

Check whether origin headers override it. USE_ORIGIN_HEADERS follows the origin Cache-Control verbatim, so one wrong header silently defeats the policy. Invalidation is also asynchronous, and negative caching keeps a 404 around briefly, so verify after both windows close rather than seconds after the request.

Related Providers

  • Google Cloud CDN: when backends already sit behind Cloud Load Balancing or Cloud Storage in the same project.
  • Cloudflare: when the origin is outside GCP or one domain needs cache rules tested on a free plan first.
  • AWS CloudFront: when origins are S3 or EC2 and signed URLs should stay inside AWS.

Community & Resources

Official docs and communities

Learning resources and tools

Original source: Google Cloud Documentation ↗