Introduction to Serverless Computing: A Beginner's Guide

Introduction to Serverless Computing: A Beginner's Guide

·

4 min read

As developers, our primary focus revolves around writing code and designing the logic that solves problems or delivers features to users. However, simply having code on your local machine doesn't make it accessible to others; you must put it online. But well, this process involves multiple configuration decisions, such as:

  • Selecting the operating system

  • Determining CPU and RAM allocations and,

  • Planning for scalability as user numbers grow, and much more.

To simplify these infrastructure management complexities, many turn to serverless models.

What is Serverless Computing?

Serverless computing is an execution model where the developer doesn't need to worry about the intricacies of managing and setting up servers. Instead, they write code in the form of functions - these are short-lived task performers. That's why, serverless is also known as Function as a Service(FaaS). These functions get triggered by specific events such as making an HTTP request or uploading any file, depending on how the developer wants users to communicate with the server.

Once your application is deployed on a serverless model, automatically allocates the required CPU and RAM, and handles scaling up when there is increased interaction.

Does Serverless Mean No Servers?

Well, servers are still in the picture, but as developers, we're abstracted from the intricacies of how they're managed. Various cloud service providers offer the flexibility of using serverless models.

When we upload our code to the cloud, the cloud provider hands us a specific URL(API endpoint) in return. This URL serves as the trigger for the functions we've written in our code.

Now, when a user hits this URL, it kind of goes like this: A request is sent to a server hosted somewhere at that very moment. The server allocates specific CPU and RAM, executes our code, and sends the response back to the user.

Because we're not directly dealing with the server, we call it "serverless."

Flow of how any request (here payment) is done.

Important characteristics

  1. Event-driven execution

    In serverless models, our code executes when specific events occur, like someone making an HTTP request. This smartly avoids running our code continuously 24/7 and only activates it when needed.

  2. Automatic Scaling

    Imagine deploying your application, and suddenly it gets hit with a ton of traffic. In such cases, you'd want to boost resources like RAM and CPU to handle all the requests.

    The cool thing is, serverless models do this automatically. They scale up when needed, saving you from manual adjustments.

  3. Pay per invocation

    With serverless platforms, you get charged based on the number of times users interact with your application and how long each interaction lasts. This means you only pay for what you use, eliminating the need to pay for resources that are just sitting there. It's a cost-effective approach.

  4. Short-lived execution

    Serverless functions are designed to be short-lived. They execute only when an event has triggered for the duration of a specific task and then terminate. This design makes resource use efficient and lets the platform allocate resources dynamically.

Challenges that come with serverless

  1. Cold-Start latency

    When a serverless function starts for the first time, it's a cold start. And it takes time because at this moment the serverless platform needs to do some setup work before it can execute your function. This setup includes initializing the necessary resources and getting everything ready to run your code.

    But subsequent requests to that function are called warm start and suffer less latency.

  2. Limited Execution Time

    Serverless platforms impose a time constraint on our serverless functions. These functions are required to complete their tasks within a specified time frame, and if the execution takes too long, the request will not be fulfilled.

Conclusion

In summary, serverless computing emerges as a remarkably efficient approach for deploying web applications and APIs. It empowers developers to effortlessly create and launch apps without getting into the technical complexities.

This method is great for a bunch of reasons. It's cheaper because you only pay for what you use. It's also really good at handling lots of work – if more people want to use your app, it automatically gets faster to keep up with everyone.

Do follow the DevHub blog on Hashnode for more such articles and join our community on Discord to keep up with all things tech! In addition to this, DevHub is partnering with a stealth SaaS Startup to bring an exclusive opportunity to get an Internship with the Startup, check it out here.