Better, Faster, Stronger - Why you should use a CDN
My crown is called content, a crown that seldom kings enjoyWilliam Shakespeare
If you're a regular visitor of the Leaping Gorilla site then you may have noticed some major improvements in speed over the last few days. That's because we've updated our site to use Amazon CloudFront - a Content Delivery Network (CDN).
What is a CDN?
A CDN acts as a middle man between your server and your users. A good CDN will take content from your servers and cache it in edge locations dispersed around the globe. These are located closer to your users so can serve the cached content faster than it would take for a full trip to your servers.
Lets take an example of retrieving a page from the Leaping Gorilla site without a CDN. Here's a typical trace route to get the home page:
TraceRoute to 184.108.40.206 [www.leapinggorilla.com] Hop (ms) (ms) (ms) IP Address Host name 1 0 0 0 220.127.116.11 xe-5-3-0.edge.dallas.level3 2 127 126 126 18.104.22.168 vlan70.csw2.dallas1.level3 3 129 129 129 22.214.171.124 ae-73-3.ebr3.dallas1.level3 4 129 130 129 126.96.36.199 ae-7-7.ebr3.atlanta2.level3 5 129 128 128 188.8.131.52 ae-2-2.ebr1.washingt.level3 6 129 130 130 184.108.40.206 ae-7-7.csw2.washingt.level3 7 131 129 129 220.127.116.11 ae-2-72.ebr2.washngt.level3 8 130 130 130 18.104.22.168 ae-41-41.ebr2.paris1.level3 9 130 130 130 22.214.171.124 ae-2-12.bar1.dublin3.level3 10 130 130 130 126.96.36.199 - 11 130 131 130 188.8.131.52 - 12 132 144 132 184.108.40.206 - 13 132 132 132 220.127.116.11 ec2-LGMACHINE.eu-west-1
CDN to the Rescue
By using a CDN we eliminate all of these lookups. We change our DNS records to point at the CDN CNAME. When a user requests the Leaping Gorilla site now they instead get redirected to the nearest edge server for the CDN. If the page that they requested has been cached this will be immediately served back - we wont even hit the server! If it hasn't been cached the edge location will use an optimised path to pull the page from your server and distribute it to the user.
How much of a difference can this make? Let's take a look at a traceroute for the Leaping Gorilla home page with a CDN enabled:
TraceRoute to 18.104.22.168 [www.leapinggorilla.com] Hop (ms) (ms) (ms) IP Address Host name 1 1 0 0 22.214.171.124 xe-5-3-0.edge3.dallas1.level3 2 0 0 0 126.96.36.199 ae-1-60.edge2.dallas1.level3 3 0 1 1 188.8.131.52 - 4 0 0 0 184.108.40.206 ae-0.amazon.dllstx09.us.ntt.net 5 0 0 0 220.127.116.11 server-54-230-120-44.cloudfront
We go from 15 hops to 5 and just look at the difference in latency! We're using our CDN's dedicated infrastructure for the lookup so it happens over blazing fast dedicated connections.
The benefits to Leaping Gorilla have been huge. We've gone from a very troubling load time of up to 6 seconds per page when accessing our EU servers from the USA to under 300ms. Also, whilst the content is served from the edge it means that it doesn't hit our server reducing load and enabling us to serve more requests with less infrastructure.
Nothing comes for free, so how much does it cost? So far - peanuts. We're looking at a monthly bill in the single digit dollar range. On tests with our clients we've been able to deliver a 10x improvement in page load from remote geographical areas whilst serving ~100GB of data/month for around $75. The kicker to this though? The edge locations reduced load on the main servers enough that we were able to thin out the server farm resulting in a net gain to the client.
I Want One!
If you are interested in setting up a CDN yourself then we would heartily recommend you use the CloudFront documentation as a starting point. If you would like our help to do this then feel free to contact us for a quote.