2
votes

I just learned that you can back a Rails app's static assets (HTML, CSS, JS, IMAGES) with Amazon Cloudfront... I read an article here that describes the process pretty well.

http://blog.codeship.io/2012/05/18/Assets-Sprites-CDN.html

I have a few questions about this CDN setup:

1> I have almost the same use case but I dont want to serve ALL my static-pre-generated (semi-dynamic) html from CloudFront CDN... I have something like 200 Million html files ~7Kb each.. so thats approximately a 1333 GB!! (search engine on rails) .. however, only 10% of those files are frequently requested by my site users.. so thats a more manageable 130 GB (long tail). The 130 GB costs about $77/month every time it leaves CloudFront (with request costs and a little leeway factored in).. but the 1300 GB costs about $770/month.. I would like to pay 90% less and only cache the data that is being frequently accessed..

2> Can I possibly only cache in cloudfront, the 10% of my dataset that is being frequently accessed? And serve the rest from my server as needed?

3> On a good day, with your current setup, my cloudfront will only have 133GB of data going out (assuming only 1 request per frequently accessed file). But on a bad day, say if a crawler requests all of my links.. it will have 1333GB of data.. How can I not overpay?

1

1 Answers

2
votes

Cloudfront is designed for asset caching, not content. The reason is quite simple: URLs.

When you use cloudfront you change your asset urls to whatever host cloudfront generates for you. That's ok for static assets, but is hell to cache content, specially content dynamically generated by rails.

That said, never use any CDN for content caching, it doesn't make sense, it's hell to maintain.