The Serverless Platform

Serverless

The term serverless refers to running a website or web application without relying on a dedicated (or a virtual private server, VPS) to host that website. I will be using website throughout this post, but this also refers to web applications, since in essence all web applications are applications that are running through a website of some sort. The term serverless may be confusing at first glance, especially for the more technically inclined, since in order for you to actually read this post, a server somewhere has to be able to send the page containing the post to your device. While true, serverless actually refers to how the webpage is “built”, meaning how the website is constructed. I will explain this in detail below.

A typical website

Let’s try to explain how a website can be viewed without a server behind it. A typical website consists of a collection of files that are hosted by a server and usually this server is also running other platforms, or services, such as a database and a blogging platform. You connect to the website as the administrator (or user) and start typing your blog post. The blogging platform stores your text in a database and all is well. When a visitor wants to view your website, their device connects to your server and the server looks up the blog post in the database, constructs the website in real time and starts sending you the constructed (or rendered) website. Depending on your website’s success, this lookup/construct process can bring down your server due to overloading it with things to do. There are ways around it, such as aggressive caching, putting a content distribution network (CDN) in front of your server, but this is outside the scope of this post. Let’s leave it at: constructing and serving a website in real time takes, well, time.

A serverless website

Now that you have a basic understanding of how websites work, let’s go into the details that make a serverless website possible. Instead of relying on your server to do the heavy lifting each and every time a visitor goes on your website, why not do the heavy lifting once, then serve a built up (ready to use) website directly to the visitor?

JAMstack

Enter JAMstack. JAMstack stand for Javascript, APIs and Markup. Javascript is a programming language that is used throughout the web and allows for processing directly on the device. Most websites today are running some form of javascript. API stand for Application Programming Interface and is a “platform” that takes the request from your device, processes it, then returns some data to your device. Markup means the web technologies that make formatting a website pretty, for example the background color, the title’s size etc. To connect the dots, markup is responsible for the things you see, javascript is responsible for communicating with the APIs and the API is responsible for processing.

Hosting things without a server

You now see that serving a website ready to use, ie. all built up and pretty, without relying on a server to render it, while doing some processing in the background to display dynamic data to the visitor is a lot faster. Way, way faster. A typical Wordpress blog will take around 500ms from the time of the first byte (you requesting the page) and the time that the server is ready to send data. A typical serverless blog, such as this, will take less than 100ms to start being served. While writing this blog, I have tested both my blog and an old familiar blog to me. The old familiar blog took 150ms from the time that I have requested it, to the time that it started being served. My blog took 80ms. Yes, this website is hosted through a serverless platform, and I will explain how that is made possible.

In order to be able to serve websites faster, you need to minimize the time that your server spends processing things before the visitor starts seeing things displayed on his device. This is made possible if you “pre-render” the website and start serving it immediately. A typical process for this is you make your changes to your local copy of the website, you push these changes to a git repository, and your serverless platform of choice “sees” this changes, pulls them to the platform, builds a new copy of the website and sends the resulting website to a CDN. This makes the website faster because due to the way a CDN works, a visitor is always close to a ready-to-use copy of your website. Doesn’t matter if your visitor is in the United States, or Germany. Most CDNs run servers in many countries, and chances are one of those servers is really close to your visitor. Compare this to a server being in the United States serving a website to a visitor from Germany.

Ending remarks

There is an old saying: What is new will be old, and what is old will be new. The web was built around the philosophy of anyone being able to host a website, and back in those old (but good) days, you had to manually type the code in order for the website to be ready. JAMstack is basically the next evolution of that: make it easier to update websites, but still serve ready-to-use websites directly to the visitor.