QubOps

Day 23 - CloudFront

AWS Cost Optimisation Advent Calendar 2024

5 min read time

#aws #cloudfront

Welcome to day 23 of the unofficial AWS Cost Optimisation Advent Calendar 2024, where every day we will be sharing new tips or tricks to help you optimise your cloud costs before Christmas 2024.

Today we are going to talk about whether using CloudFront saves, or costs you money.

What is CloudFront?

CloudFront is a content delivery network (CDN) service provided by Amazon Web Services (AWS). It speeds up the delivery of your content by caching it at edge locations around the world. This means that when a user requests your content, it is served from the nearest edge location, rather than your origin server.

How does CloudFront save you money?

  1. Reduced data transfer costs: CloudFront provides a more generous free tier for data transfer out than other AWS services. By serving your content from edge locations, you can reduce the amount of data transferred from your origin server, potentially saving you money.

  2. Reduced origin costs: By caching your content at edge locations, you reduce the load on your origin server. This can lead to cost savings, as you may be able to use a smaller, cheaper server.

  3. Reduced latency costs: By serving your content from edge locations, you reduce the latency experienced by your users. This can lead to increased user satisfaction and potentially increased revenue.

We will be focusing on the first two as the third is not directly related to cost optimisation.

If you are running a workload such as an API or a website that is accessed over the internet, your primary costs will be powering those servers and the data transferred between you and your users.

By putting CloudFront in front of your services, you can reduce the cost for both of these.

Reduced data transfer costs

CloudFront provides 1TB/month of data transfer out to the internet for free. When compared to using an Application Load Balancer for example, you get 100GB free each month.

So if you are exceeding the free tier on your load balancer, you could save money by simply sticking CloudFront in front of your load balancer. There are no data transfer fees between CloudFront and your load balancer.

In addition, you can benefit from the content being served via edge locations which means that your users will experience lower latency.

Reduced origin costs

CloudFront provides very configurable and a highly effective cache system.

Although many web frameworks and tools provide their own caching mechanisms, these usually require additional servers or processing power to operate and all this comes at a cost.

By offloading the caching to CloudFront, you can reduce the load on your servers, meaning you need fewer of them.

But not so fast, CloudFront is not free. How does it compare to doing this yourself?

Unfortunately there is no magic formula to calculate this, as it depends on how cacheable your service is, and which requests are causing the most work on your servers.

The low hanging fruit would be websites which are mostly static content, such as your marketing website or a blog. These are the easiest to cache and the most likely to see a cost saving. For many of these cases you can power a very high traffic website through CloudFront with a tiny server in the backend just to feed the cache.

For APIs, and websites that require sessions with dynamic content, the cost benefit will be less clear and some time will need to be spent analysing the caching strategy.

In terms of pricing, as we mentioned, the Free Tier is very generous. You get:

  • 1 TB of data transfer out to the internet per month
  • 10,000,000 HTTP or HTTPS Requests per month
  • 2,000,000 CloudFront Function invocations per month
  • 2,000,000 CloudFront KeyValueStore reads per month
  • 1,000 free cache invalidations
  • Free SSL certificates

So it is possible to power a reasonably busy website with an S3 backend for close to free.

The main costs you will need to consider when comparing compute costs are:

  • Cache invalidations
    • If you handle a whole folder, each file costs as an invalidation
  • Requests per month
    • If you have a very high traffic website, you may need to pay for requests
  • Function calls / KeyValueStore reads
    • CloudFront supports running functions and provides a key/value store for these functions.

Conclusion

Whilst the savings on data transfer can often make a switch to CloudFront a no-brainer, the cost savings on the origin side are less clear cut.

Some investigation will be needed to ensure that introducing CloudFront is not an anti-pattern for your specific use case.

That said, there are many scenarios where CloudFront can be a game changer in terms of cost savings due to it's caching ability and generous Free Tier.

As always, if you need any help with this contact our friendly team.

To be the first to know when the next edition is published, follow us on LinkedIn, X, BlueSky or subscribe to the RSS feed.

Join our newsletter for Cost Optimization tips and tricks

By subscribing you agree to our Privacy Policy and provide consent to receive updates from our company.