How a CloudFront Cache Key Without the Country Header Showed German Shoppers Prices in Rupees for 43 Minutes
← Back
November 30, 2026Infrastructure8 min read

How a CloudFront Cache Key Without the Country Header Showed German Shoppers Prices in Rupees for 43 Minutes

Published November 30, 20268 min read

14:09 UTC. Support channel: "Three tickets in ten minutes from Germany. Prices on the product page say ₹2,499. The cart says €29.99. One customer sent a screenshot. They think we're running a bait-and-switch."


the scramble

The shop serves prices from GET /api/prices/:sku. The handler reads the CloudFront-Viewer-Country header, maps the country to a currency (DE to EUR, IN to INR, everything else to USD), and returns a number already converted and formatted. The checkout service prices the cart server-side from the user's billing country, which is why the cart showed euros and the page showed rupees.

We had shipped one change at 13:26: a Cache-Control: public, s-maxage=300 header on the price endpoint. The origin was running at 70% CPU during the daily campaign window, and prices change at most a few times a day. Five minutes of edge caching looked like free headroom.

Priya, on call, opened the incident channel at 14:14. First theory, hers: the FX conversion service was returning a bad rate, and somebody had mapped the wrong rate table to EUR. That would explain a wrong number. It would not explain the wrong symbol.

the hunt

I pulled the price service's own logs for SKU tee-0412 and grouped by resolved currency:

$ rg 'sku=tee-0412' price-service.log | awk '{print $6}' | sort | uniq -c 212 currency=USD 88 currency=INR 61 currency=EUR

The origin was resolving currency correctly for every request it received. 61 EUR responses for a day of German traffic is far too low though, which meant most German requests never reached the origin at all. That pointed away from the FX service and toward something sitting in front of it.

Second theory: a frontend bug, a stale client-side cache or a service worker serving old prices. I tried it in a clean browser profile with a German exit node. Still rupees. Not client-side.

Then I stopped using the browser and used curl, faking the country the way CloudFront would have:

$ curl -sI https://shop.example.com/api/prices/tee-0412 | rg -i 'x-cache|age|cache-control|vary' cache-control: public, s-maxage=300 x-cache: Hit from cloudfront age: 187 vary: Accept-Encoding $ curl -s https://shop.example.com/api/prices/tee-0412 {"sku":"tee-0412","display":"₹2,499","currency":"INR"}

From a German IP, a Hit from cloudfront with age: 187 and an INR body. The response had been generated 187 seconds earlier for somebody else. Whoever hit that edge location first after the entry expired decided the currency for everyone who followed, until the entry expired again.

the find

CloudFront only forwards a header to the origin if the cache policy says so. The country headers are not forwarded by default. We had them working because our origin request policy listed CloudFront-Viewer-Country. That is a separate thing from the cache policy, and the cache policy is what builds the cache key:

# cache policy (what we had) HeaderBehavior: none QueryStringBehavior: all CookieBehavior: none # origin request policy (what made the handler "work") HeaderBehavior: whitelist Headers: [CloudFront-Viewer-Country]

The origin request policy sends the header to the origin on a cache miss. The cache policy decides whether two requests are the same object. With the header absent from the cache policy, a request from Germany and one from India produced identical cache keys. Before 13:26 this was invisible, because nothing was cacheable: the handler returned no Cache-Control and CloudFront's default TTL on that behavior was 0. The new header is what turned a latent misconfiguration into a live one.

The Vary header did not save us either. CloudFront ignores Vary for anything except Accept-Encoding, and our handler never set Vary: CloudFront-Viewer-Country anyway.

the fix

First, stop the bleeding. At 14:31 I removed the s-maxage from the handler and created a wildcard invalidation on /api/prices/*. Wrong prices were gone from every edge by 14:52, 43 minutes after the first ticket and 86 minutes after the change shipped.

Then the proper fix. Currency is now part of the cache key explicitly, and the handler no longer infers anything from the viewer country on a cached path. The edge normalizes the country into a small set of values with a CloudFront Function, so the cache does not fragment into 200 variants:

// viewer-request CloudFront Function function handler(event) { var req = event.request; var country = (req.headers['cloudfront-viewer-country'] || {}).value || 'US'; var map = { DE: 'EUR', FR: 'EUR', NL: 'EUR', IN: 'INR' }; req.headers['x-currency'] = { value: map[country] || 'USD' }; return req; }
# cache policy (now) HeaderBehavior: whitelist Headers: [x-currency]

The handler reads x-currency and returns Vary: x-currency for anyone debugging with curl later. Three currency buckets means three cache entries per SKU, which is still a 99% reduction in origin traffic against the uncached baseline.

the aftermath

  • Impact: about 4,100 page views showed a currency different from the visitor's billing country across the window. 19 support tickets. Nobody was overcharged, since checkout prices server-side, but a few customers said they'd abandoned carts.
  • A staging test now requests the same URL with CloudFront-Viewer-Country set to DE, then IN, and fails if the second response carries x-cache: Hit with the first one's currency.
  • Any change that adds a cacheable Cache-Control header to an endpoint now requires listing, in the PR, every request header the handler reads. We found two other endpoints reading Accept-Language with the same gap.
  • We added age and x-cache to the price endpoint's debug logging, so "was this served from the edge" is a one-line answer next time.

I had read the two policies as one setting split across two screens. The origin request policy decides what the origin sees. The cache policy decides which requests count as the same page. I'd only ever set the first.

Share this
← All Posts8 min read