At some point on 2023 we were discussing about costs and pagespeed, I quickly pointed out that the slow performance and spike in bandwidth cost was caused by the usage of .gif images, at first the team was reluctant about this but a few days later I came up with a report provided by the Amazon S3 service in which you can get save an access log of the hosted files and later process it by using Amazon Athena.

S3 Access logs documentation

The report was curiously enlightening, as I was able to find access to .gif files with a size over 100mb, usually the .gif images were the cover of the post and in our main listing page there were several of them loading even thought users were not accessing the post. Without any doubt the .gifs were a problem we needed to address.

After discussing this with the team in the following day we were trying to figure it out the best way to address the issue and for sure the first proposal was stop using .gif images but you know another team claimed that using .gifs was important for the post as they sell more when they have .gifs, also we proposed using Youtube videos as we already supported that but it looked like it was going to make their work more complex.

At some point we mentioned about using a CDN and as we were hosting on AWS the expected thought was using an AWS Cloudfront distribution, at first I tried to turn down this proposal as CF provides 1TB of outgoing bandwidth for free but after that we will still pay $0.1 per GB, which based on our monthly expenses (over 15TB) was only going to reduce only around a bit over 100$

After our daily meeting I started to investigate how we can address this situation and a few hours later I evaluated several CDNs and the final option was cloudflare as they offered a free plan enough for our needs. Also it was super easy to implement we just got another domain for the CDN and in a few days everything was set and working.

This is how much cloudflare was able to serve during the first month after the implementation:

15TB of Bandwidth usage throught cloudflare

Usually Cloudflare is caching around 80% of the traffic, sometimes more as the next graphic shows.

Cached content

This is how AWS bill the bandwidth:

  • First 10 TB: $0.09 per GB
  • Next 40 TB: $0.085 per GB
  • Next 100 TB: $0.07 per GB
  • More than 150 TB: $0.05 per GB

Based on that the 15.28 TB we were paying $1,381.17 in bandwidth, meaning that our yearly expenses for this reason will be near the $16,574.04, if we consider that cloudflare is caching 80% of the traffic the total savings looks like this:

Total cost without CDN Total Cost with CDN Savings Yearly
$16,574.04 $3,381.72 $13,192.32

It was for sure really cool that we avoid paying all that but using a CDN comes with other benefits that impact directly on page speed, in another post we will discuss the benefits of images transformations and also using next generations formats as an option to speed up your website.