/api/usersLesson 7 · Cache at the edge
Sometimes, skip the origin entirely.
A local CDN sits in front of the complete Lesson 6 origin. Product reads are cached for 15 seconds; a cache hit returns straight from the CDN and never reaches the Edge Load Balancer, an API Gateway, or a service.
Interactive caching lab
Watch a MISS populate the cache, then a HIT skip everything downstream.
Request Products twice inside 15 seconds. The first response is stored at the CDN; the second returns from that cache alone.
GET /api/products is cached, for 15 seconds. User and Order routes always bypass the cache. This rule lives in the CDN configuration and is intentionally changeable.http://127.0.0.1:7712/api/products
Start the lesson, then request Products twice.
Execute a request to inspect the original response.
Execute a request to inspect the response headers, including X-Cache-Status.
CDN → waiting/api/products/api/ordersObserve the cache
Did this request reach the origin?
A HIT answers from the CDN alone. A MISS or BYPASS travels the complete Lesson 6 path before the CDN can respond.
- 1Start the lessonThe trace will separate a cache answer from a full origin round trip.
The first Product request after a start or a cleared cache is always a MISS: nothing is stored yet, so the CDN forwards it to the origin and keeps a copy. A second request inside the 15-second TTL is a HIT and never leaves the CDN.
Start Lesson 7.
Origin is skipped on HIT.
Origin is skipped on HIT.
Origin is skipped on HIT.
Origin is skipped on HIT.
What this teaches
Cache responses closer to the client.
This is a good point to introduce a CDN (Content Delivery Network) and response caching. A CDN sits closer to the client than any part of the origin and can answer frequently requested, cacheable content directly.
If the requested content is already cached, it returns directly and the request never reaches the origin:
On a cache miss, the CDN forwards the request through the full origin chain and may store the response so future requests can be served directly.
Reduced origin traffic
A HIT never reaches the Edge Load Balancer, a Gateway, or a service.
Reduced backend load
The Catalog tier answers fewer requests during traffic spikes.
Faster responses
One cache lookup replaces several internal routing decisions.
Serves from the edge
In production, requests are answered from a location closer to the client.
Local CDN
Answers cacheable reads directly and forwards everything else to its configured origin.
Lesson 6 infrastructure
The full Edge Load Balancer, API Gateway, and Catalog Load Balancer chain, reached only on a MISS or BYPASS.
Note: real systems usually have several load balancers
A CDN does not discover its destination automatically. Its distribution is configured with an origin hostname or an origin group.
Cache behaviors can map request paths to the desired origin. DNS, Anycast, or a global traffic manager can then resolve that origin hostname to the appropriate regional or edge load balancer. From there, internal load balancers continue routing traffic to the correct gateway and service instances.
Origin groups can also define a primary and secondary origin so the CDN can fail over when the primary origin is unavailable.
Anycast gets a proper explanation in Lesson 8 — though note it is used in the opposite direction there. This note is about how the CDN finds its origin; Lesson 8 is about how a client finds the CDN.
What this gives us
- Cache hits skip the entire origin chain
- Lower backend load during traffic spikes
- Faster responses for cached content
- An explicit, per-route cache policy
- The origin remains authoritative on a MISS
What still remains
- This single CDN container is now a SPOF of its own — if it stops, everything stops, cached or not. Lesson 8 (bonus) shows why that worry mostly dissolves in the real world, where a CDN is one address served from many locations at once.
- Cached content can be stale for up to the TTL window
- Every non-cached route still crosses the full origin chain
- Cache policy must be chosen deliberately per endpoint