How to check if CDN is caching your video stream
When you're streaming video, ensuring that your CDN (Content Delivery Network) is properly caching your video is incredibly important.
Without proper caching, your stream could lead to several major issues, including high data transfer costs, poor viewer experience due to buffering or slow load times, and in the worst case, overloading your server and crashing the event.
Caching allows the CDN to store parts of your video stream closer to your audience, reducing the strain on your origin server and ensuring smoother playback for your viewers.
In this tutorial, we'll guide you through the steps to check if your video stream is being cached by your CDN, helping you avoid these problems.
Why caching matters
If your CDN is not caching your video content:
- Increased Data Transfer costs: Without caching, every viewer who watches your stream pulls the video directly from your origin server, leading to higher data usage and associated costs.
- Poor viewing experience: Buffering, delays, and interrupted streams are common when caching isn’t enabled, driving viewers away.
- Server overload: If your origin server is handling too many requests, especially during high-traffic events, it may fail under the load, causing your stream to crash and potentially halting your event.
Now that we understand why it’s crucial, let’s dive into how you can check if your CDN is caching your video.
We're going to use CloudFront CDN as an example, but this tutorial is applicable to any other CDN.
Let's begin!
Create a Web Player
Once your video stream is coming, create a Web Player:
Go to Web Players section and click "Add New".
1. Name your player. I’ve named mine "Cached Event" for easy reference.
2. Select your input source, such as an SRT or RTMP server.
3. Adjust any other necessary settings.
Save your player.
Open the Web Player
In the Web Players section, click "Info" (i).
Copy the Web Player URL.
Inspect your Video Stream
Now it's time to check if your CDN is caching the video:
1. Open the Web Player in your browser.
Press play to start loading video chunks.
2. Right-click on the player and select Inspect (this opens the browser's developer tools).
3. Go to the Network tab. This will show you all the network requests being made by the player.
4. Look for files with the .ts extension in the list (these are video fragments). Click on one of the .ts files.
5. In the Headers tab, under Response Headers, find a line that says X-Cache.
6. If you see "Miss from [CDN name]", this means that the video was NOT fetched from the CDN — it’s being pulled directly from the origin server.
This is likely because you’re the only viewer, and the CDN hasn’t cached the video yet (the cache hasn’t been "warmed up").
Simulate a second viewer to check caching
To confirm that the CDN is caching your video, you’ll need to simulate having a second viewer.
1. Open the web player in a new browser tab (or even a different browser) and play the video again.
2. Follow the same steps as before to inspect the network requests and locate the .ts files.
3. Compare the .ts files with the same numbers from both tabs.
4. This time, you should see "Hit from [CDN name]" in the headers. This means that the CDN has cached the video fragment, and it's now being served from the cache rather than directly from the origin server.
You’ve successfully checked if your CDN is caching your video stream, ensuring that your video content is being delivered efficiently.
This method works for any CDN and is crucial for maintaining a reliable, cost-effective, and high-quality streaming experience.
Why this is important
By simulating the second viewer, you confirm that your CDN is working correctly and caching the video stream. This process ensures that:
- Future viewers won’t overload your server: Once the cache is warmed up, the CDN will serve video fragments to your viewers, significantly reducing the load on your origin server.
- Better viewer experience: Cached videos load faster, play smoother, and reduce buffering, making for a much more enjoyable experience.
- Cost efficiency: By caching the video, your CDN minimizes data transfer from the origin server, saving you from high data transfer costs.
You might also like
Our series of tutorials about setting up CloudFront.
- Part I — Setup CloudFront CDN for Live Events
- Part II — Caching .ts video fragments for HLS
- Part III — Set up a business domain name
Follow us on social media
LinkedIn • Reddit • Instagram • Facebook • Youtube • X (Twitter) • Discord