Before I commit to KeyCDN for my little blog I wanted to check if CloudFront is better. Why? Because I already have an AWS account set up, familiar with boto3, it's what we use for work, and it's AWS so it's usually pretty good stuff. As an attractive bonus, CloudFront has 44 edge locations (KeyCDN 34).

Price-wise it's hard to compare because the AWS CloudFront pricing page is hard to read because the costs are broken up by regions. KeyCDN themselves claim KeyCDN is about 2x cheaper than CloudFront. This seems to be true if you look at cdnoverview.com's comparison too. CloudFront seems to have more extra specific costs. For example, with AWS CloudFront you have to pay to invalidate the cache whereas that's free for KeyCDN.

I also ran a little global latency test comparing the two using Hyperping using 7 global regions. The results are as follows:

KeyCDN on Hyperping.io
KeyCDN on Hyperping.io

CloudFront on Hyperping.io
CloudFront on Hyperping.io

Region KeyCDN CloudFront Winner
London 27 ms 36 ms KeyCDN
San Francisco 29 ms 46 ms KeyCDN
Frankfurt 47 ms 1001 ms KeyCDN
New York City 52 ms 68 ms KeyCDN
São Paulo 105 ms 162 ms KeyCDN
Sydney 162 ms 131 ms CloudFront
Mumbai 254 ms 76 ms CloudFront

Take these with a pinch of salt because it's only an average for the last 1 hour. Let's agree that they both faster than your regular Nginx server in a single location.

By the way, both KeyCDN and CloudFront support Brotli compression. For CloudFront, this was added in July 2018 and if your origin can serve according to Content-Encoding you simply tell CloudFront to cache based on that header.

Although I've never tried it CloudFront does have an API for doing cache invalidation (aka. purging) and you can use boto3 to do it but I've never tried it. For KeyCDN here's how you do cache invalidation with the python-keycdn-api:


api = keycdn.Api(settings.KEYCDN_API_KEY)
call = "zones/purgeurl/{}.json".format(settings.KEYCDN_ZONE_ID)
all_urls = [
    'origin.example.com/static/foo.css',
    'origin.example.com/static/foo.cssbr',
    'origin.example.com/images/foo.jpg',
]
params = {"urls": all_urls}
response = api.delete(call, params)
print(response)

I'm not in love with that API but I know it issues the invalidation fast whereas with CloudFront I heard it takes a while to take effect.

Comments

Jonathan Kosgei

This page says Cloudfront has 176 edge locations - https://aws.amazon.com/cloudfront/features/.

Kris

Thank you for your article.

I'm newbie in website related, my website only to shows my portfolios, just in case my clients ask for it.

I'm using KeyCDN since 2013, it's very simple and I was following their tutorial, and all works perfectly.

I saw a lot of giant website using amazon S3 and cloudfront, so I want to try it for my new website.
To be honest it's not newbie friendly at all, I got a headache by looking there are dozens or maybe hundreds link on their UI. I feel intimidate. lol

I'm gonna stick to KeyCDN for now :)

Peter Bengtsson

That sounds perfectly fine. KeyCDN is a great product. I've come to understand and appreciate some of the more advanced options in CloudFront and the options you have with Lambda@Edge. But if I could do it again I think I would set up a super simple web server that runs 24/7 that handles all the advance error handling, header wrangling, URL rewriting.

And now CloudFront supports Brotli. So perhaps in a sense, CloudFront has/is *more* but I'm deeply skeptical that it matters and you're that deep in the advanced options, you are probably doing it for a living.

Your email will never ever be published.

Related posts