Challenges of using a CDN (Part 2)

In this episode of Leaseweb Tech Talks, we explore more on the challenges when using a CDN and the importance of caching CORS headers in CDN setups. Our host Pamily, and Product Manager Shanook Jaansen break down real-world challenges faced by Leaseweb customers, showing how not caching these headers can lead to server overloads, downtime, and increased costs. Learn the key role of the Vary header in solving these issues and discover best practices for optimizing your CDN configuration.

Real-world CDN pain points: Caching CORS headers 

Not caching CORS (Cross-Origin Resource Sharing) headers might seem like a small oversight, but it can lead to big problems, especially during high-traffic events. In this episode, Pamily and Shanook explore why this common misconfiguration leads to unnecessary pre-requests hitting origin servers, ultimately causing performance degradation and even downtime. 

“When these CORS pre-requests aren’t cached, the origin server gets hit with every single one, over and over again,” explains Shanook. “It not only increases server load but also affects performance for the end user.” 

They share an example of a customer who experienced server overload while streaming a live event. Because the system didn’t cache the CORS headers, each request triggered a round trip to the origin server. With thousands of users accessing the content simultaneously, the compounded requests brought the system down. 

Understanding the problem 

Before browsers allow access to a resource hosted on a different origin, they perform a “pre-flight” request to verify if it’s permitted. This verification relies on CORS headers like Access-Control-Allow-Origin. 

If those headers aren’t cached: 

  • Each user request triggers a new pre-request 
  • The origin server gets flooded with redundant traffic 
  • Latency increases and operational costs rise 

It’s essentially a scaling bottleneck many teams don’t account for, until it’s too late. 

How to avoid it 

There are two key ways to avoid these issues: 

  1. Cache CORS headers at the CDN layer. 

This ensures the CDN can respond to pre-requests directly, reducing pressure on the origin. 

  1. Use the Vary header properly. 

This instructs caches to serve the correct version to each requester by differentiating responses based on origin.

“Without the Vary header, your cache doesn’t know which version of the response to serve,” says Shanook. “That breaks the whole CORS process.” 

By properly setting the Vary header and caching CORS responses at the CDN layer, organizations can significantly improve resilience, reduce latency, and keep costs under control. 

Watch the full episode 

Want to hear the full discussion and learn best practices for optimizing your CDN setup? 

Watch Episode 7 now 

Leave a Reply

Your email address will not be published. Required fields are marked *