Skip to content

Deliver content from the edge

11 min reading

Choose cacheability, origin/edge responsibilities and invalidation for a declared object

Page details

System Design · Follow a request

11 min reading · 24 min with practice

Sources

Published · Last edited:

Prerequisite: Define service and API boundaries. For basics, use the independent System Design foundations.

More
20px

Hypothetical scenario. Many promotion visitors request the same public product page. Dev proposes serving saved responses from the edge. Maya switches the example visitor’s market and asks whether that saved price is still the answer the visitor requested.

Dev: “The saved response could avoid an origin request.”

Priya: “Before counting the saving, which requests are allowed to share it?”

The next design decision is eligibility for reuse. Follow one representation through its identity, age and delivery, then calculate the work that an assumed hit rate avoids. A quick response from the wrong market does not satisfy the catalogue brief.

Which requests may share this representation?

A content delivery network places serving capacity near users and can reuse stored responses. The origin remains responsible for producing the authoritative representation under Northwind’s application rules. An edge hit avoids some origin work, but the response is acceptable only if it matches the requested product, market, currency and other relevant dimensions.

A cache key identifies the stored representation selected for reuse. Northwind’s public catalogue contract has no private visitor fields, but it does include market and currency. If these change the answer, the cache policy must distinguish them. Ignoring a dimension can return a technically fresh response for the wrong request.

HTTP caching provides standard controls for storage and reuse. RFC 9111 defines freshness, validation and the role of fields such as Vary. Use the origin’s representation contract to decide the relevant dimensions, then choose how the selected CDN expresses them. Do not assume every request header automatically becomes part of a cache key.

Decide what may be shared

Public product information can be a candidate for shared reuse. Account details, tenant-specific prices or access-controlled records require a different decision. Encrypting the connection does not make a shared cache entry private. A cache key that merely contains a product identifier does not distinguish two callers with different permissions.

Keep the present scope narrow: Northwind’s anonymous public listing for one explicitly identified market and currency. Do not extend that decision to the later permission-aware document assistant. The later security lessons will examine authority across background work and data paths; here the boundary is simply that this representation must genuinely be shareable.

Cache eligibility precedes the shorter pathA visitor asks the edge for a product, market and currency. An eligible stored representation can return directly. A miss or required validation reaches the origin, which supplies a representation and its cache policy.Visitor requestMarket + currencyEdge decisionEligible hit?OriginMiss / validateStored representationIdentity + age + policy
A shorter path helps only when it returns the permitted representation.

Preserve age through two cache layers

Hypothetical scenario. A source representation is already thirty seconds old when stored at an inner cache. It spends ten seconds there, eight more at an edge cache and two in delivery. The selected source-evidence age is 30 + 10 + 8 + 2 = 50 seconds. Creating a new edge response must not restart that evidence clock. HTTP response age and application-specific price evidence are related observations with different definitions.

Preserve age through two cache layers — selected design evidence
Stored evidenceExampleReuse condition
Variant keyQ7 / UK / GBP / view-v2All dimensions match
Validatorrepresentation tagValidate selected variant
Source evidencerevision and evidence timeAge survives every layer
Accumulated source age reaches fifty seconds; an extra cache does not renew the source observation.Accumulated source age reaches fifty seconds; an extra cache does not renew the source observation. Origin to Inner cache: 1 · evidence already 30 s old; Inner cache to Edge: 2 · after 10 s residence; Edge to Visitor: 3 · 8 s + 2 s delivery.OriginInner cacheEdgeVisitor1 · evidence already 30 s old2 · after 10 s residence3 · 8 s + 2 s delivery
Accumulated source age reaches fifty seconds; an extra cache does not renew the source observation. Enlarge the diagram to inspect its labels; the surrounding records and explanation give the text alternative.

Choose a key containing every dimension that changes the reusable result: product, market, currency and representation version in this example. Personalized or permission-dependent content also needs an explicit sharing rule. An ETag validates a selected representation; it is not a universal authorization or source-freshness certificate.

Versioned immutable assets avoid overwriting cached bytes under one name, but the pointer selecting the active asset still changes. Collapse simultaneous eligible misses only within a compatible key and authority scope. A withdrawal needs a propagation or current-check rule whose bound is part of the product contract; an ordinary cache lifetime cannot promise instantaneous revocation.

Derive what the origin no longer does

Hypothetical worked example. Keep the selected fifteen catalogue reads per second. Suppose an illustrative interval has twelve eligible edge hits and three misses each second, with each miss producing one origin request. The hit share is 12 ÷ 15 = 0.8, or 80%. Origin demand is 15 × (1 − 0.8) = 3 reads per second.

Using the selected 2,000-byte response, payload sent from the edge to visitors is still 15 × 2,000 = 30,000 bytes per second. Origin-to-edge payload for those misses is 3 × 2,000 = 6,000 bytes per second. The difference is 30,000 − 6,000 = 24,000 bytes per second in this simplified accounting. Headers, validation, retries and other objects are excluded.

This is a selected hit pattern, not a promised cache ratio. If a new deployment changes every representation key, the cache can be cold. At zero hits, origin demand returns to fifteen reads per second. Retain the original capacity argument rather than sizing the origin only for the warm-cache average.

A cache lifetime does not reset the price clock

Northwind’s sixty-second rule concerns the age of the price evidence when delivered. HTTP freshness concerns how a stored response may be reused under its caching policy. Those clocks need not start together. An origin can generate a new HTTP response around a product record that was already old.

Choose a product record already forty-five seconds old when the edge stores its response. After twenty seconds in the edge cache and a further one second to deliver and present, its selected evidence age is 45 + 20 + 1 = 66 seconds. A thirty-second cache lifetime would not prevent this result, even though the response spent only twenty seconds in that cache.

Under those selected assumptions, the remaining allowance before the sixty-second limit is 60 − 45 − 1 = 14 seconds at storage time. That arithmetic suggests an application-aware limit or revalidation decision; it does not make a fourteen-second setting universally correct. Upstream lag, clock interpretation and delivery variation must be accounted for in the real contract.

Choose validation and versioning deliberately

Validation asks an origin whether a stored representation remains suitable, using protocol mechanisms such as validators. It can reduce transferred payload when unchanged, but still involves communication and origin-side work. A validation response does not automatically establish an application fact that the origin never checked.

Versioned immutable asset names are useful for resources whose contents truly do not change under that identity. A product price at a stable URL is a different object. Updating a price may require expiry, validation or an invalidation mechanism. State which caches are reached and what happens during propagation rather than promising that a purge immediately changes every response a visitor can see.

Do not use an old value during origin failure unless the application contract explicitly permits it. A stale picture may be acceptable where a stale promotion price is not. Availability and freshness are product decisions attached to the representation, not one global caching switch.

In the wild: the standard separates storage from reuse

RFC 9111 is a real primary contract for HTTP caching. Its distinction between storing a response, considering it fresh and validating it is useful precisely because those are separate decisions. Northwind adds its own product-age and identity rules on top. A CDN deployment should be checked against both layers.

The accompanying NGINX caching lecture gives a concrete implementation view. Treat vendor-specific controls as implementation options; a feature being available does not establish that the chosen configuration uses it correctly. Keep the intended policy readable independently of product syntax.

When a fast cache returns the wrong market

Hypothetical failure scenario. Northwind distinguishes market through a request field, but the shared cache keys only by product URL. One visitor populates a response for a different market. The next visitor receives it quickly over a protected connection. Hit rate and latency improve while the application result becomes incorrect.

The fix starts with representation identity. Include the required distinction in the reuse policy, invalidate incorrectly keyed entries and verify the original visitor outcomes. Shortening the lifetime alone leaves a window in which the wrong response can still be reused. Adding more origin workers does not repair the key.

Place the edge where reuse has value

Use edge caching when many requests can share an eligible representation and avoiding the origin serves a meaningful latency or capacity goal. Its value falls when responses are effectively unique, permissions are difficult to represent safely or required freshness forces frequent origin validation. A CDN may offer other delivery functions, but those need their own justification.

Northwind will cache only the declared public representation, preserve its identity dimensions and retain capacity for cold origin demand. The next checkpoint combines this decision with deadlines and healthy routing. Instead of adding another component, you will ask what the whole path can still promise when the worker set changes and the cache is cold.

Challenge the proposed mechanism

The edge validates successfully after a product is withdrawn. What further fact is required?

Reveal the design reasoning

Identify which authority the validator covers and whether it includes current eligibility. If it validates only unchanged bytes, consult the withdrawal authority or apply the declared propagation bound. Serve unavailable when no permitted current result can be established.

Decision and reconsideration: Preserve variant identity and evidence age across layers. Revisit cache policy when the revocation bound becomes stricter.

Test the reuse contract

  1. Twelve of fifteen requests hit. How much selected origin demand remains?

    Count misses under the stated model

    Three reads per second, assuming one origin request per miss and no additional validation or retries. A cold cache can return origin demand to fifteen, so three is not the capacity requirement for every state.

  2. A response has a thirty-second lifetime. Is a price already forty-five seconds old safe for twenty seconds of cache residence?

    Preserve the evidence clock

    No under the selected sixty-second rule and one-second delivery allowance: 45 + 20 + 1 = 66 seconds. HTTP response residence cannot erase age that existed at the origin.

  3. Two markets use the same URL. Can a short lifetime replace a correct key?

    Separate identity from age

    No. Reusing the wrong market’s representation is incorrect even immediately after storage. The key and reuse policy must distinguish all dimensions required by the representation contract.

Northwind can now explain the conditions under which the edge saves origin work. Page 10 removes a worker and starts with a cold cache, asking whether the assembled path still supports the original promise.

Northwind decision log

Share only public representations with complete identity dimensions.
Account for origin evidence age as well as cache residence and delivery.
Carry cold-cache origin demand into the request-path checkpoint.

Go deeper: reuse, validation and routing