Caching is a data policy, not a speed switch
In ecommerce, a cache can reduce latency and requests to applications, databases and catalogue services, but it creates a copy with its own age. The operational challenge is not merely achieving a high hit ratio. Teams must decide which responses may be reused, for how long, and what should happen after they become stale. An anonymous category page has different constraints from a price, inventory position, cart or order status. Without that distinction, an apparent performance improvement can produce inconsistent information or a sudden surge against the origin.
RFC 9111 distinguishes fresh responses, stale responses and validation with the origin. Freshness permits reuse without contacting the origin; an expired response needs an explicit rule for validation or temporary stale serving. Design should therefore start with the commercial meaning of data rather than one universal TTL. The target is an observable cache with bounded staleness and predictable behaviour when the cache is cold, unavailable or affected by a broad invalidation.
Inventory routes, dependencies and staleness tolerance
Build a cacheability matrix
List pages, APIs and fragments with their owner, authoritative source, change frequency, audience, variation dimensions and maximum acceptable staleness. Editorial catalogue pages, anonymous product detail pages, images and guides are often suitable. Promotional prices and availability may be cached only with short windows, targeted invalidation and authoritative validation before an order is committed. Carts, accounts, checkout, payment, orders and personalised responses must not accidentally enter a shared cache.
The matrix should also describe failure. During an origin error, is a slightly old product description preferable to a hard error? For stock, what can the interface say without promising unverified availability? A recorded decision prevents teams from copying a generic directive onto incompatible endpoints. Document who can change the policy and how the organisation proves that responses involving cookies, authorisation or personal data use private or bypassed paths.
Design cache keys without mixing users or variants
Control cardinality while preserving correctness
A sound key contains only dimensions that genuinely change the representation: normalised path, language, currency or price list when relevant, content version and approved filter parameters. Do not place personal identifiers, tokens or complete cookies in shared keys. At the same time, do not omit a dimension that alters the result, or two markets might receive the wrong price, tax treatment or availability. RFC 9111 describes the role of URI, method and fields named by Vary; verify actual behaviour across the CDN, reverse proxy and application cache.
Normalise query strings and equivalent values through an explicit allowlist. Tracking parameters should not multiply identical objects, while real catalogue filters may need separate variants. Record a value-format version for application caches. A deployment that changes a schema should either read older values safely or use a distinct namespace. Deleting every value at once when a format mismatch appears can create a refresh wave larger than the original issue.
Combine TTLs, validators and stale windows
A TTL is not a number to choose once and forget. It follows from change rate, the impact of old data and origin capacity. Use max-age or equivalent policies for freshness, validators such as ETag or Last-Modified when they are correctly generated, and the Age header, which RFC 9111 defines as an estimate of time since origin generation or validation, including transfer and cache residence. no-cache requires validation before reuse; no-store and private address different needs and are not interchangeable.
RFC 5861 defines stale-while-revalidate, which can serve an expired response temporarily while revalidation happens, and stale-if-error, which can permit a stale response for specified failures. Windows must match the data. Cloudflare documents a provider-specific asynchronous flow in which requests during revalidation can receive UPDATING in CF-Cache-Status; do not assume identical behaviour everywhere. Keep stricter thresholds for price and stock, and validate both against the authoritative service when committing an order.
Invalidate entities and dependencies instead of purging everything
Use tags and idempotent events
Associate cached objects with stable entities such as product, category, collection or campaign. A product update can invalidate its detail page, categories and related fragments without emptying the entire catalogue. Cloudflare’s cache-tag documentation explains that a tag purge forces a later MISS value in CF-Cache-Status and therefore an origin fetch. That is useful, but its operational cost matters. Version the tag taxonomy and keep its growth under control.
Invalidation events should be repeatable, traceable and tolerant of duplicates or variable ordering. Store an event identifier, entity, expected version, timestamp and purge result. If a message is lost, periodic reconciliation can compare source and cached versions. When purge fails, the TTL remains a safety net rather than the primary strategy. Avoid a global purge after every import: it concentrates recomputation into one moment and raises the risk of saturating downstream systems.
Prevent cache stampedes and thundering herds
When a popular key expires, many requests may attempt the same computation. Apply request coalescing: one forwarded request retrieves the reusable response, while compatible waiting requests share that result. Cap concurrency and request rates toward the origin, and define what callers receive when retrieval fails or exceeds its time budget.
AWS Builders’ Library warns that a cold or unavailable cache can transfer an atypical spike to a dependency and cause throttling or a brownout. Test the service with caching disabled, apply backpressure or load shedding, and size the origin for an explicit degraded scenario. Start with keys proven hot by production measurements and verify the origin impact of every planned purge.
Test cold states, slow origins and concurrent invalidation
Create repeatable tests for hits, misses, expiry, revalidation, slow origin, errors, purge and incompatible formats. Drive realistic traffic into a cold cache and check whether coalescing limits concurrent origin calls. Update a product while revalidation is running and verify which version may be served. For price and availability, simulate a change during checkout to prove that order confirmation uses the authoritative system and handles any difference explicitly.
- Verify that account and checkout responses are always private, bypassed or not stored.
- Measure delay from event to purge and to the first coherent response at every layer.
- Exercise event loss, duplicate retrieval requests and origin responses that exceed the time budget.
- Test rollback and mixed deployments with different cached-value formats.
Measure quality, load and actual staleness
For Cloudflare implementations, pair hit ratio with the MISS, BYPASS, STALE and UPDATING values of CF-Cache-Status. Also observe Age, origin request rate and latency, coalesced waiters, purge errors and delay, values served beyond threshold, and p95 and p99. For application caches, add CPU, memory, evictions and key cardinality. Segment by route class and data type; one average can hide stale stock behind a large number of static-image hits.
Set thresholds and owners before an incident. A declining hit ratio might be expected after a release, while rising misses combined with origin latency need action. Connect traces or request identifiers to cache status, logical key and data version without recording personal information. A reliable cache does not promise that stale data never exists. It makes duration, frequency and impact visible and keeps every deviation inside a deliberately approved bound.
A faster cache because it is governed
A sustainable path starts with an inventory and risk matrix, then adds minimal keys, justified TTLs, entity invalidation, coalescing and degraded-state tests. Checkout and mutations stay outside shared caching; price and stock are confirmed by the origin before an order is accepted. The cache remains a reversible optimisation rather than a hidden dependency.
AE Digital Agency can support architecture, observability and load testing through our ecommerce systems services. To define a cache policy and a verifiable invalidation plan for your stack, talk to our team.
- cache ecommerce
- cache invalidation
- cache stampede
- cdn
- request coalescing
- stale-while-revalidate
- ttl
- osservabilità
Frequently asked questions
Which ecommerce pages are suitable for a shared cache?
Anonymous catalogue and editorial content are common candidates. Accounts, carts, checkout, payments and orders should use private or non-stored paths.
How can an ecommerce store prevent stale prices and availability?
Use short windows, entity-level invalidation and observability, then always reconfirm price and stock with the authoritative system before committing an order.
What prevents a cache stampede?
Request coalescing, concurrency limits, bounded stale serving and backpressure stop many requests from recomputing one key together.
Is a global purge a sound invalidation strategy?
Usually not: it turns many accesses into simultaneous misses. Prefer product, category or campaign tags and load-test the origin after purge operations.
Sources
- RFC 9111: HTTP Caching — RFC Editor
- RFC 5861: HTTP Cache-Control Extensions for Stale Content — RFC Editor
- Revalidation — Cloudflare
- Caching challenges and strategies — Amazon Web Services
- Purge cache by cache-tags — Cloudflare
- Cloudflare cache responses — Cloudflare
Related articles
Digital Systems · 6 min read
Ecommerce SLOs: measure checkout and orders with error budgets and burn-rate alerts
An operational method for defining checkout SLIs and SLOs, using error budgets in decisions and building actionable multi-window burn-rate alerts.
Digital Systems · 7 min read
Ecommerce distributed tracing: diagnose checkout and orders with OpenTelemetry
An operational method for tracing checkout and orders, propagating context, correlating providers, protecting data and sampling without losing incidents.
Server & Domains · 6 min read
Cloudflare for Black Friday peaks: cache rules that hold the traffic
Which pages of an online store to cache on Cloudflare, which to always exclude, how to write cache rules and how to purge the cache when prices change.
