How to reduce Amazon Cloudfront costs? How to reduce Amazon Cloudfront costs? wordpress wordpress

How to reduce Amazon Cloudfront costs?


I'm not quite sure what's the difference between Cloudfront and S3.

That's easy. S3 is a data store. It stores files, and is super-scalable (easily scaling to serving 1000's of people at once.) The problem is that it's centralized (i.e. served from one place in the world.)

CloudFront is a CDN. It caches your files all over the world so they can be served faster. If you squint, it looks like they are 'storing' your files, but the cache can be lost at any time (or if they boot up a new node), so you still need the files at your origin.

CF may actually hurt you if you have too few hits per file. For example, in Tokyo, CF may have 20 nodes. It may take 100 requests to a file before all 20 CF nodes have cached your file (requests are randomly distributed). Of those 100 requets, 20 of them will hit an empty cache and see an additional 200ms latency as it fetches the file. They generally cache your file for a long time.

I'm not using S3 and don't know if I should

Probably not. Consider using S3 if you expect your site to massively grow in media. (i.e. lots of use photo uploads.)

Is there a way to reduce the costs? Maybe using another CDN service?

That entirely depends on your site. Some ideas:

1) Make sure you are serving the appropriate headers. And make sure your expires time isn't too short (should be days or weeks, or months, ideally).

The "best practice" is to never expire pages, except maybe your index page which should expire every X minutes or hours or days (depending on how fast you want it updated.) Make sure every page/image says how long it can be cached.

2) As stated above, CF is only useful if each page is requested > 100's of times per cache time. If you have millions of pages, each requested a few times, CF may not be useful.

3) Requests from Asia are much more expensive than the from the US. Consider launching your server in Toyko if you're more popular there.

4) Look at your web server log and see how often CF is requesting each of your assets. If it's more often than you expect, your cache headers are setup wrong. If you setup "cache this for months", you should only see a handful of requests per day (as they boot new servers, etc), and a few hundred requests when you publish a new file (i.e. one request per CF edge node).

Depending on your setup, other CDNs may be cheaper. And depending on your server, other setups may be less expensive. (i.e. if you serve lots of small files, you might be better off doing your own caching on EC2.)


You could give cloudflare a go. It's not a full CDN so it might not have all the features as cloudfront, but the basic package is free and it will offload a lot of traffic from your server.

https://www.cloudflare.com


Amazon Cloudfront costs Based on 2 factor

  1. Number of Requests
  2. Data Transferred in GB

Solution

  1. Reduce image requests. For that combine small images into one image and use that image https://www.w3schools.com/css/tryit.asp?filename=trycss_sprites_img (image sprites)
  2. Don't use CDN for video file because video size is high and this is responsible for too high in CDN coast