Spent some time whiteboarding and testing the CDN path. User sends a request, it hits the CDN edge first, not the origin. The edge checks the CDN CACHE. If there’s a hit, it returns the response immediately. If there’s a miss or no response, it forwards the request to the Origin Server, gets the image, runs the optimization, stores it in the cache, then serves it back to the user.
This is why the Vary and Cache-Control headers I added last week matter so much. Without them, the CDN would serve the same WebP to a browser that only accepts PNG. With the proper headers, the cache stores separate variants per Accept header.
I also built the fallback logic shown in the diagram. If the origin is down, the CDN can still serve a stale cached response instead of a 500. Tested it by killing the origin locally and the edge still returned the last good image for 60 seconds.
This isn’t just theory anymore. The diagram is now how the worker actually routes traffic. Next step is adding cache purging by URL pattern so updates propagate faster.
Log in to leave a comment