The CDN Edge — Best Practices For Managing Your Content in Cache

Eric Klein
disney-streaming
Published in
4 min readOct 5, 2018

Content Delivery Networks (CDNs) have become a vital layer of the internet ecosystem. Once a term used to discuss companies focused on distributed networks of proxy servers, the solutions now provided in this space are far more encompassing.

CDNs are no longer just focused on distributed datacenters designed to scale to deliver static content. Now they are inclusive of edge computing, video streaming, mobile content acceleration, load balancing and DDoS Security, amongst other offerings. CDNs are central to serving a large portion of the internet content today.

And yet, for all of their features, functions and form, they still remain relatively obscure. Difficult to penetrate networks with internal architectures that are not easily understood. You may find out only a little bit about where your content is deployed at any given time, but to truly gain deep insight into where a specific individual request may be satisfied and to debug how your content is being delivered, you need specific ways to gain this insight.

In a continuing series, we hope to focus on best practices for engaging with cached content, the latest features on CDNs and some of the upcoming advancements in the industry.

This first entry in the series covers the specific aspects of the headers you need to be aware of to analyze your content cache health. A crucial aspect to debugging your CDN experience, Headers are the building blocks to understanding each and every request.

Know Your Headers

A simple spot to start in debugging any CDN request is to know your HTTP headers. These headers are crucial to being able to evaluate any request that comes in. Some key headers to keep an eye on include:

  • Max-Age: Typically classified as TTL, or Time to Live, max-age (as well as s-maxage) is actually the HTTP header that is tracking this value. The Max-Age will provide insight into how long the object has remaining in cache. S-MaxAge which is more intermediate cache focused. In the case of a presence of both values S-MaxAge will take precedent.
  • Expires: Another crucial aspect to determining the TTL of an object, Expires provides the exact date and time where an object will no longer be considered valid, resulting in a content refresh to ensure that it is still a valid cacheable object.
  • Last-Modified: Want to know how old the file is that you are requesting? The answer lies in the Last-Modified header. While this does not necessarily tell you how long the object has been in the CDN cache, this header does inform you when the object you were requesting was last updated. With content that has a low TTL or is frequently updated, this is typically a good indication that cache is working as it should
  • E-Tag: The E-Tag is a unique identifier per piece of content. E-Tags are typically a good indication of the uniqueness of an object in cache. If the object changes, the e-tag will change. With this simple header, you can verify that the object you’re serving and the object in cache are exactly the same. It also allows for an easy way for CDNs to verify that content is fresh — when it’s leveraged.
  • Status Codes: We all know that Status Codes such as 200, 206, 403, 404, 503, 504 are crucial to any response indicating the health of the object, but did you know that certain CDNs have specific ways they handle these status codes and respond? 404s, while traditionally indicative of an object not being found, can also be the result of a CDN temporarily caching an error code. Make sure to note the difference based on the Max-Age of the error response. What about a 503 — Service Unavailable — or 504 — Gateway Timeout? These could indicate CDN issues or content origin issues. To dive further you need to be very cognizant of the status code you receive back and take the next step accordingly.

These are just some of headers that we look at when evaluate requests but are definitely the first few that help give an indication into how content is behaving and the role cache is playing in the requests.

A Simple cURL Can Be Your Friend

Performing a simple GET request on your content via Curl, or through a proxy tool such as Charles, is a key way to understanding CDN behavior. All CDNs provider debug headers that, when passed along with your request, will give you details back on what is happening with your content.

These debug headers, easily available by request from your CDN’s technical team or via an internet search, provide back a wealth of information that gives you an almost instant way to analyze the behavior of your content inside the Content Delivery Networks.

In the case of some of these debug headers, you’ll find information such as the TTL of the object — both as you set it, as well as how the CDN is caching it. You’ll also discover where your content is served from and whether or not it was being served by the CDN’s cache or being fetched from your origin (Hit/Miss).

Just The First

In a subsequent post, we’ll go into the above debug headers in detail and how to use them to analyze your CDN experience. We’ll also explore some alternative ways to test your content in cache, dive into ways to leverage proxy tools and more to further evaluate and explore the way your content is cached on the edge.

Photo by JohnsonGoh on Pixabay

--

--