I love Cloudflare. I’ve always been a fan of their service and their generous free plan, which they’ve never backtracked from. They still offer unlimited bandwidth with very few limitations. Users have stories about serving terabytes of data per day without Cloudflare knocking on their door to upgrade.
We, too, use Cloudflare under the hood, which enables us to offer unlimited bandwidth for our users as well.
This might make people wonder: Why pay for a CDN when Cloudflare is free? When I started using Cloudflare, I thought that too.
But when you compare it to a traditional CDN, Cloudflare does have a few shortcomings:
1. Unreliable Caching Policies
With a traditional CDN, if you set cache-control header, you can be sure that your files will be cached on the edge according to the header.
Cloudflare does respect the cache-control headers, but not always. I have served files with public, max-age=31536000, immutable
header, and it still results in cache-miss, even when the request comes from the same location and edge.
Cloudflare is able to offer unlimited bandwidth because they have peering arrangements with large number of ISPs and hosting providers. They help providers save T1 bandwidth cost by caching the most frequently resources at their edge servers.
Naturally, they can’t cache every file indefinitely. Considering their free plan, the storage costs would be astronomical. I suspect that Cloudflare caching heavily depends on the frequency of the requests for the file. So, if a file hasn’t been requested in a while, it gets purged from the cache, irrespective of what the headers with which it was served with.
2. Unreliable Latency
While latency from a conventional CDN is usually < 80ms, with Cloudflare, I have frequently seen it to be in 150-300ms. To be sure, Cloudflare network is super-capable, files from jsdelivr are frequently served in less than 30ms.
High and inconsistent latency is just a product of how Cloudflare works as I covered it in the last section. Not all files will be replicated across all of their edge nodes, as it all depends on how frequently they are requested and from where.
This is a cost which one has to keep in mind when using Cloudflare instead of a CDN. That said, the trade-off might be minor as web pages can still load consistently fast even with a high latency. For most websites, Cloudflare would work well-enough to serve most of their visitors.
3. Lack of Logging, Vary, Origin Shield, Custom Origin
Most CDNs allow you to access request logs which can be super helpful to extract insights from Traffic. Cloudflare offers this, but only on their Business/Enterprise plans. Similarly, Vary Cache can be useful to server different content based on user’s location, device, etc. Cloudflare only supports this for Images, and only based on Accept
headers.
Another useful feature is Origin Shield, which helps reduce requests to your origin server by looking for the file from other edge locations. On traditional CDNs, this can significantly cut down traffic. I have seen requests for the same file drop to zero when enabling it. Cloudflare has something similar called Tiered Cache, but like many Cloudflare features, the way it works is complicated, and isn’t guaranteed same level of benefits as Origin Shield.
With a traditional CDN, you can pick a hostname (Origin) and the file will be fetched from there. So, you can run a CDN directly over, say, a S3 Cloud bucket. Cloudflare works at your website domain level, and doing this is something like that is not possible.
Cloudflare does provide a few things that help with the problems that I have stated. For example, Cache Reserve can both reduce latency and eliminate requests to your origin. Argo Smart Routing can act towards reducing latency. Advanced features of Tiered Cache on Enterprise plans can introduce another layer of caching to respond to requests even faster.
However, these all are paid services and don’t fully address the issues I mentioned.
Conclusion
Cloudflare is a fantastic service with a generous free plan, but it’s a fairly complex product. CDN is just one of the things they do, and so, it’s not surprising that they have some quirks and limitations compared a traditional CDN.
For a casual user or a small website, it might not matter and free plan can go a long way, but if you need predictable, reliable caching, or features commonly found in other CDNs, you might need to pay for Cloudflare’s premium services or look elsewhere.