Understanding Serverless Architecture & AWS Lambda Functions

Understanding Serverless Architecture & AWS Lambda Functions

Even if you are just getting started in the dev field you mush have heard the term "serverless", right?

So, today we are going to cover what serverless architecture is and compare it with traditional server based approach.

Oh and we will also take a look at AWS lambda Functions which is a serverless implementation that AWS provides on their platform.

So let's dive in 💦

Server Based Approach

If you are a backend developer or you are creating APIs for a product be it REST APIs or HTTP, it can be any language python or maybe a framework like NodeJS but in any case to run that code what do you need?

A SERVER.

right?

Let's take AWS as reference for creating the server. AWS provides EC2 to created virtual servers in the cloud.

EC2

Amazon Elastic Compute Cloud (Amazon EC2) provides on-demand, scalable computing capacity in the Amazon Web Services (AWS) Cloud. Using Amazon EC2 reduces hardware costs so you can develop and deploy applications faster

~ Amazon docs


            A basic architecture diagram of an EC2 instance within a VPC.

When creating an EC2 instance or any server for that matter you need to configure a lot of things for example what OS, how much memory, how many cores and so on.

And when traffic increases on the server you have to handle that yourself. For example you might consider ASG(auto scale groups) to handle increasing traffic. You need to upscale or downscale the server as and when required to handle the demand as well keep the cost in control.

  • Pricing for this service is on per-hour basis and since it is a server it is run continuously 24x7.

So, in summary everything in EC2 is manually configured, which is advantageous or disadvantageous depending on needs.

Advantages of EC2

  1. Reliability

  2. Security

  3. Flexibility

  4. Cost Saving

  5. Complete Computing Solution

  6. Elastic Web-Scale Computing

  7. Completely controlled

Now let's take a look at serverless architecture...

Serverless?

So as the name suggests no server right?

Serverless technologies feature automatic scaling, built-in high availability, and a pay-for-use billing model to increase agility and optimize costs

So it is an "on-demand" service. For example I create a function to get weather data in a serverless architecture let's say lambda function.

WORKING: What happens is that function gets deployed but is not running right now. It is initially at a "STOP" or "DEAD" state. And only when it get's "triggered" will an instance be created with all the configurations done automatically and the function will be run and then after that again the instance will close itself off.

💡Is it running 24x7?

ANS: No. It only starts on a trigger.

💡What happens when multiple users request the service?

ANS: Multiple instances are created parallelly so that no user experiences a delay.

So by creating instances parallelly serverless architectures manage scalability automatically without any manual configuration.

  • Pricing for this architecture is based on the number of requests