How is it possible to host a website without a server?
It is actually not possible to host a website without a server or a physical computer that serves the content of the website. So, serverless architectures refer to applications that depend on a third-party services that manage all the infrastructure for you - the mighty cloud service provider like Amazon Web Services (AWS), Google Cloud Platform (GCP), Microsoft Azure, IBM Cloud and Alibaba Cloud (Aliyun).
There are many concepts behind serverless that I could not explain in a single post. I shall introduce them from time to time on my blog. Typically, a serverless architecture should allow you to pay only when a service is delivered or resources are used. It does not make sense to pay for something that you did not use right?
Imagine the scenarios below:
Scenario 1: A website that provides information to readers.
- The usual concurrent readers on the website is around 10.
- You want to run a campaign that will have 1,000 people accessing the website at a particular instance, say 12 am of a single day to get a freebie.
On a traditional situation where you own the server, you have to call the service provider to insert a new server the week before you want to launch the campaign. And you start to incur extra cost. Most probably you can not return the server after the event either.
For a shared server, on the other hand, you can change to a higher package that can withstand the load but they will usually ask you to sign for a deal of 3 months at least. Which is not a good deal for you either.
Moving on to the cloud, where you still manage the infrastructure like an Elastic Compute. You are safe in this situation. Just scale up to a larger instance and after the event, scale down to the original instance that you are using. Perfect, nothing to worry.
Scenario 2: A game that requires connecting to the server.
- The first day of the launch, there is little to no person playing the game for about 1 month.
- On a fine day after a YouTuber review the game, there are 100,000 downloads within 24 hours.
I will put the traditional server management and shared server aside for this scenario. Let us talk about the cloud that we have already discussed.
Yes, indeed, you can quickly scale up or start a new load balancer when the load could not handle and you start to see people complaining. Perfect situation and nothing much to worry except for the extra cost that incurs after the peak and before the cooldown threshold for the load balancer to close down the server.
The game changer - serverless architecture
What if I tell you that there is a way that you do not need to worry about all those scaling up and down at all? That is the benefit of using a serverless architecture, a new way of using the cloud.
Every API call or action performed on your website, you are charged for as low as 100 milliseconds per block of payment.
Serving the website is charged based on the number of request and bandwidth only.
If nobody visits your website, you pay nothing.
Sudden spike where many people visit your website at the same time? You pay according to the number of visitors.
Pay only what you use!
Speed regardless of location
In the today's technology, we want to have our website loaded almost immediately without any buffer or loading. But a typical loading speed of a web page usually depends on a server location. "A server" could only exist in a particular physical location.
This provides a bad experience when you are trying to load a website across the region. For example, loading a web page from the United States and the server is hosted in Australia; The underwater fibre optics cable might add up a little latency to the website loading.
Before going further on the topic, I will share my speed test result of my website from multiple different locations using an online tool. The online tool uses a browser from a different region to load the same website; Some useful information is recorded, like the time taken for the website to load for the first time and second time (loading speed for the second attempt can be used to test for caching optimization), the number of files loaded (if there is any error loading any file will be recorded here as well).
I managed to achieve an average of 2.4 seconds and 1.2 seconds for the first visit and second visit respectively from 22 different locations around the world.
That is mainly thanks to a product from my serverless cloud provider, AWS Cloudfront. A global content delivery network (CDN) service that securely delivers data, videos, applications, APIs or any files that you upload and configured with low latency and readily available in edges of AWS.
AWS Cloudfront have a global network of 114 Points of Presence (103 Edge Locations and 11 Regional Edge Caches) in 56 cities across 24 countries
Let's look at the image below of where they are located. The number of edges and the snapshot are correct and updated as of the day I wrote the blog post.
There are more edges coming from time to time to give your user the best and lowest latency possible.
Optimization for better user experience
There is another tool that I used to measure the loading and rendering speed that you would experience on my webpage. This PageSpeed Insight developer tool analyses your website using mobile and desktop to give you a score of how well your website is optimized.
There are some really good optimization suggestions that you can follow to provide the best user experience to users that come to your website.
If you found that most of the things listed on optimizations already presented instead of optimization suggestions. Congratulations, you have done a good job in optimizing your website. Your user would love to visit your website more often thanks to the optimization you have done for them in providing the best user experience you could ever provide.
I will end this segment with my optimization score of 99/100. I hope that I could further improve the page speed optimization to a perfect score of 100/100 in the near future.
Little recap of what I have shared
I hope you have known a little more about serverless architecture presented by modern cloud providers. They are really a game changer in a lot of cases. They ensure high availability and reliability while keeping costs to a minimum.
Good Read on Serverless Architecture: How Does Alibaba Cloud Power the Biggest Online Shopping Festival?
I have also introduced 2 tools that I used to measure my website performance.
- Loading speed from multiple locations (optimized with the help of CDN edges)
- Loading optimization (optimized separately using a couple of techniques)
If you like the content that I have shared, I hope that you could share it with your friends instead of keeping it to yourself. Do comment below if you have any questions and thoughts or you like the content you are seeing - this will certainly motivate me to write more content.
The next post will be about, "Hosting your first website using serverless architecture on AWS". This will be my first tutorial series with some code and screenshots that you can follow along to get your website hosted and only pay when people visit your website. Hope you look forward to it as much as I do!