How to deploy a platform that can handle infinite traffic with zero brain power

Aaeaaqaaaaaaaas3aaaajgi4ywjmzgezltc1mzktndlmmi05mguwltc5ownhywvkm2qzna

Here it is. What you have all been waiting for. The ultimate guide to scalability:

 

  • Host static files on Amazon S3
  • Deliver them via a Content Delivery Network such as Amazon Cloudfront

 

Yep, that's it. Sound too good to be true? Blogs with similar titles usually are, but at hoot we have actually achieved it. 

 

 

Above is a live screenshot from our admin dashboard captured at the time this was being written. It illustrates the previous 30 days of usage across our entire media hosting platform. 

We handled 3.23 million requests in the last 30 days. Not too shabby. The best part is that I spent 0 hours making sure that the system was consistently up and running. 

 

How exactly do we support 2.3 million requests without losing sleep?

 

 

The impact of hoot not being available on a client's website would be cataclysmic for both parties. Not only would our clients lose faith in us, but it would also make them look bad to their customers. This isn't an option, so we designed the entire platform to run from statically hosted files.

 

 

What the hell are statically hosted files and what is the alternative? 

 

 

The alternative is traditional server architecture. It adds multiple layers of processing to each request. Each layer is limited by the capacity of the devices involved, so if one is overloaded with traffic then the entire system will go down. It also slows down the entire system because of the added processing performed by each layer. 

 

A system built to run off of static files has two main benefits:

  • The platform will perform as fast as the user's internet connection. 
  •  Hosting static files on a system such as S3 makes it infinitely scalable. 

 

However, there are a couple drawbacks:

  • Changes to files don't to take effect immediately due to caches expiration
  • Any modifications made to a file needs to be pushed up to S3

 

 

 

Why aren't static files used to host every platform? 

 

 

To be frank, what is displayed to the end user changes too often to take advantage of this. Hoot enjoys this luxury because the photos that comprise the 3D product experience and the code that runs it are rarely altered.

 

 


Above you can see that these fashionable cowgirl boots for sale on Zappos are almost out of stock. Zappos not only has to advertise the current availability of an item to browsers, but also has to prevent them from purchasing items that are out of stock. This would be quite arduous to accomplish with a static site. Not impossible, but probably not worth the extra effort. 

 

 

 

How Content Delivery Networks bend the laws of Physics 

 

 

 

Light travels through fiber optics at 128,340 miles per second.

 

 

Let's say hypothetically I am in Singapore and open hoot on a site. Since we host our files in Amazon's data center in Virginia, the round trip on the internet for a request and response is 19,492 miles.

 

 

 

According to Einstein's law of relativity the minimum time required for my request to be served up is 0.151 seconds or 151 milliseconds

 

 

 

 

Technically my request should take a lot longer because my internet connection is weak and the request is traveling through thousands of additional miles of twisted cables, rather than in a straight line.

 


Now let's fire up Chrome Developer Tools to test how long the initial request for hoot actually takes. 

 

 

 

 

Only 66.11 milliseconds!?!? How did we do that?

 

Pure magic.

 

Well... more accurately the magic of a CDN. 

The data didn't actually have to travel across the Pacific Ocean to Virginia because our CDN copies our static files and makes them accessible all over the world. 

 

 

 

 

Above is a map of Amazon's edge locations that extend across the globe.This ensures that our application loads rapidly no matter where in world the request is made. Better yet, every single one of our clients has a CDN endpoint dedicated to them.

 

This platform and infrastructure may not be the ideal solution for everyone, but if you can make it work there are plenty of benefits. Our next blog will dive  deeper into how content, such as this blog, is hosted through static files enabling us to handle dynamic content gracefully. Be sure signup for our email newsletter in our website footer to receive notifications about new posts and updates!

 

Questions/Comments? Leave them below, we try to answer every one.