
Scaling Your Static Site to a Global Market for a Fraction of the Cost on AWS - emforce
https://medium.com/@elliot_f/scaling-your-static-site-to-a-global-market-for-a-fraction-of-the-cost-on-aws-12d23f30f877
======
ddrmaxgt37
I'm surprised no one is mentioning Netlify in the comments.

~~~
pdog
What is Netlify?

~~~
needcaffeine
[https://www.netlify.com/](https://www.netlify.com/)

~~~
exodust
When I go to
[https://www.netlify.com/pricing](https://www.netlify.com/pricing) in Firefox
I get this error:

 _Corrupted Content Error The site
at[https://www.netlify.com/pricing](https://www.netlify.com/pricing) has
experienced a network protocol violation that cannot be repaired._

Never seen this error before. Seems okay in Chrome and IE, so not sure what's
going on in Firefox.

~~~
sofaofthedamned
I get this quite a lot in Firefox, especially on O365. It's usually fixed by
doing a hard-refresg (ctrl-Shift R or something).

------
kkielhofner
AWS and the like make a killing from the basic fact that most web devs don't
know anything about the real costs of bandwidth (a blind spot, if you will).

HE.net is currently advertising 10gig ethernet for $1300/mo. Obviously there
are various scaling issues associated with this but the basic premise still
holds - AWS and other cloud services need major pressure to push their
bandwidth prices down.

~~~
jauer
This is less about cost of bandwidth and more costs of having edge POPs around
the world.

With cloudfront (or any other edge cache system), you get TCP termination
closer to end-users so the site loads faster, particularly if you have users
around the world. Dropbox case study:
[https://blogs.dropbox.com/tech/2017/06/evolution-of-
dropboxs...](https://blogs.dropbox.com/tech/2017/06/evolution-of-dropboxs-
edge-network/)

Edge cache bandwidth costs quite a bit more than the not quite bottom of
barrel IP transit that HE.net is selling.

------
PowerfulWizard
I have set up some sites the same way, the only ugly part for me was that I
wanted to use the features of S3 web hosting interface, but restrict all
traffic to come through CloudFront. This blog post (not mine) describes the
problem and the approach:
[https://abridge2devnull.com/posts/2018/01/restricting-
access...](https://abridge2devnull.com/posts/2018/01/restricting-access-to-a-
cloudfront-s3-website-origin/)

~~~
zackbloom
Have you thought about using Cloudflare Workers instead? It's pretty easy to
host from a bucket: [https://developers.cloudflare.com/workers/recipes/static-
sit...](https://developers.cloudflare.com/workers/recipes/static-site/)

~~~
PowerfulWizard
I wanted to stay fully AWS, it was for personal projects so it is more about
convenience so I didn't even consider other CDNs.

------
varunramesh
Right now, I am hosting my personal site and blog on S3 + Cloudflare for 6
cents / month. I use Middleman, because I feel that it offers more flexibility
than Hugo.

------
meritt
Cost-comparisons aside, the massive speed improvement makes me think he didn't
have caching configured correctly with Cloudflare and his PHP backend (thus
defeating the entire point of the CDN aspect).

I'm guessing a couple of Cache-Control: headers would have provided similar
latency improvements.

~~~
emforce
Comparisons were done with CloudFlare on static site, it's been a very long
time since the site was based on Laravel and PHP.

I had set Browser Cache Expiration to 1 month within my CloudFlare settings as
was luckily screenshotted within a previous article:
[https://medium.com/@elliot_f/my-journey-into-web-speed-
optim...](https://medium.com/@elliot_f/my-journey-into-web-speed-optimization-
part-2-52fc48c3b106)

I'm _fairly_ sure that I had some speed optimizations set within my Nginx
server block. Unfortunately, I don't have the Nginx config file to hand
anymore as I've (somewhat stupidly) deleted the snapshots without taking a
backup.

~~~
meritt
I'm no Cloudflare nor Cloudfront expert but these should be apples-to-apples
comparisons and seeing that _huge_ disparity in latency makes me think it's
most likely a configuration issue, as all comparisons I've ever seen claim
they perform roughly about the same: [https://blog.latency.at/2017-09-06-cdn-
comparison/](https://blog.latency.at/2017-09-06-cdn-comparison/)

Specifically though we're talking about how long Cloudflare caches your
content on their proxy/edge servers. Browser caching is irrelevant for this
discussion, as speed tests of this nature should always be performed on a
clean request.

~~~
emforce
I can't claim I am either, unfortunately. I required assistance ensuring the
certs were in place and my configuration was correct when doing the migration.

And just to clarify, based on some of the articles I've read, I actually think
CloudFlare may be a better choice of CDN, this post just highlights one way of
achieving a global-scale website and doing it in such a way that it's
resilient and cheap as chips!

------
tapirl
GAE is far better than AWS for static sites. No cost for medium scale static
websites (50,000 pageviews/day), CDN built-in.

------
ecesena
Why not Github pages? Has anyone measured performance? CDN is always an option
you can add on top, if you don't like Github's one.

------
EvilEndures
Spaces + BunnyCDN is even cheaper. ;)

$6/month = 250GB of static websites + domain registration fees.

If you want to get really cheap, OVH's cloud storage is basically free but you
lose https. ($.01/GB of traffic/storage roughly)

~~~
Zaheer
Link for Spaces? Couldn't search it since was fairly generic term.

~~~
EvilEndures
Sorry. Spaces = Digital Ocean's Spaces product. $5/month. Park a CDN in front
of it with Edge rules and you get a similar setup.

~~~
minxomat
Spaces will get a native CDN this year if DOS roadmap is to be believed.

~~~
EvilEndures
The problem with Spaces as static hosting is it doesn't handle
index.html/index.htm correctly so you need a CDN with edge rules.

------
drudru11
Does this require invalidating the main page in cloudfronts CDN when you add a
blog post or article?

~~~
nkristoffersen
If you want the updated site to be available immediately then you must
invalidate the cache.

I do it as the last step in my CI/CD process:

    
    
        - aws configure set preview.cloudfront true
        - aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_ID --paths '/*'
        - curl https://google.com/ping?sitemap=$SITEMAP_URL

~~~
drudru11
Thx. I was hoping there was a way to avoid that extra cost. Also, thx for
sharing your code to do this.

------
1996
why can't he use the free cloudflare?

A static website cached by cloudflare seems very vanilla.

Also, why S3? this seems very easy to do with Linode or anything else
similarly cheap or cheaper ($20 gets you a KVM VPS with 2 Gb nowadays)

Unless you have to regenerate constantly, all it needs is nginx, to serve the
pages to Cloudflare edges when thry drop out of the cache

~~~
emforce
I was previously using Cloudflare in conjunction with a Linode server. The
disadvantage of this, however, is that you need to ensure that one server
never goes down otherwise anyone hitting a cold cache would see the site down.

Also, why do you need a server at all? If you are doing nothing but serving
static files then why incur the overhead of maintaining LetsEncrypt
certificates and writing Nginx config files? AWS provides a simple interface
in which you can view and manage your static files without having to ssh into
a server.

On the point of price, I'm predicting my total cost of hosting for a site
serving roughly 40-45k users per month will be roughly $7/month. All whilst
minimizing the amount of administration time required and monitoring of a more
traditional system.

Hope this clarifies this, would be keen to hear any counter thoughts!

~~~
1996
Sure! here are my counter thoughts: What if your site changes every 5 minutes,
and is about 100Mb?

12x24x100= lots of mb per day

S3 costs (if only for the bandwidth) will be greater than a server with a fair
share unlimited connection

Also, cloudfront non free plans will kill you - again because of the bandwith.

~~~
giobox
> What if your site changes every 5 minutes, and is about 100Mb?

This is probably an exceptional rate of change for the _vast_ majority of
static sites.

~~~
bigpicture
> This is probably an exceptional rate of change for the _vast_ majority of
> static sites.

I also doubt that many static sites have much "overhead" related to
maintaining nginx config files and Let's Encrypt certificates.

~~~
outworlder
Sure, but then there's the whole overhead of maintaining a server.

~~~
ramses0
Clarify this: "The difference between zero servers and one server is much
larger than the difference between 100 servers and 101 servers"

The person you're talking to is likely thinking of the "100=>101" case, not
the "0=>1" case.

