What is the Serverless concept?

Published on:

What is the Serverless concept?

When I first heard the word serverless, I thought it referred to projects that don’t need a server and only need a client XD but that interpretation of mine was wrong. In Serverless, we actually do have servers, and good ones at that, but we no longer have to worry about all the maintenance involved. This maintenance includes:

  • Installing the operating system
  • Hardware scalability
  • Server configuration
  • Security updates
  • Installing and configuring a web server (e.g. nginx, apache)
  • Load balancer

Meaning you focus only and only on writing your code, and you shove the serious and difficult responsibilities onto someone else XD

Pretty nice, isn’t it? So basically, it’s not that there is no server, there is, but you don’t have to worry about it anymore. In a way, you could say the name of this architecture is Server’s Concernless.

A look at other types of servers that might get mixed up with serverless

Since the types of servers keep getting more and more numerous, I think it’s better, before adding a ton of extra textual explanation, to simply compare it with some examples that sometimes have similar features to serverless and see what’s going on:

Comparison criterionShared ServerDedicated ServerVPSPaaSServerless
Basic definitionSharing a physical server and its resources among hundreds of sitesA completely dedicated physical server in a datacenterA virtualized layer (VM) with dedicated resources on a host serverA managed platform for directly running and Deploying codeAn event-driven architecture with instant code execution and automatic scalability
Access and control levelZero, only access to the control panel100%, full Root/SSH and Bios/Hardware accessHigh, full Root/SSH access to the virtual OSLimited, access only to application settings and Environment VariablesZero, no access to the OS or infrastructure
Infrastructure and OS managementHandled by the providerEntirely your responsibilityEntirely your responsibilityHandled by the providerHandled by the provider
Pricing modelFixed monthly/yearly rental (very cheap)Fixed monthly/yearly rental (very expensive)Fixed monthly/hourly rental based on reserved resourcesBased on the number of Instances and reserved RAM/CPUExactly based on actual usage (number of Requests + execution time in milliseconds)
Cost at zero traffic (Idle)Pay the full costPay the full costPay the full costPay the full cost$0 (Scale to Zero)
Scalability (Scaling)Almost zero, requires upgrading to a higher hosting planManual and difficult, requires ordering and adding physical hardwareSimple Vertical, upgrading RAM and CPU with RebootAutomatic Horizontal, quickly adding a new containerAuto-scaling from 1 to 10,000 simultaneous executions in a few milliseconds
Cold Start problemNoneNoneNoneNoneYes, a short delay on the first request after some idle time
Execution Timeout limitationDepends on Web Server settingsNo limitationNo limitationNo limitationYes, limited to a few seconds to a few minutes (e.g. 15 minutes in AWS Lambda)
WebSocket and Long-running supportVery limited or disabledExcellent and completeExcellent and completeExcellent and completeWeak/complex
Isolation and securityLow, a vulnerability in one site can threaten the othersMaximum, hardware is completely isolatedGood, isolation at the hypervisor/VM levelHigh, isolation at the Container levelVery high, each request runs in an isolated Micro-VM/Sandbox
DevOps complexity and maintenanceZeroVery highMedium to highLowVery low
Examples of well-known providersBluehostHetznerHetzner Cloud, DigitalOceanAWS Elastic Beanstalk, Google App EngineAWS Lambda, Cloudflare Workers, Google Cloud Run, Vercel
What kind of project needs this?Small corporate sites, simple WordPress blogsBanking systems, very large databases, heavy processingMedium-sized projects, standard APIs, Dockerized AppsStartups, MVPs, projects where development speed mattersEvent-driven APIs, systems with sudden and sinusoidal traffic

As we saw in the table, if we want to compare our server to a house, each one would look like this:

  • Shared Server: Student dormitory
  • Dedicated Server: Empty private house
  • VPS: Private rental house
  • PaaS: Hotel
  • Serverless: Hourly hotel

I’ll try to write about these as a Service things later too (e.g.: IaaS, PaaS …)

When should we use serverless?

There are good reasons to use serverless, and I’ll write down some of the most important ones. For the first and second reasons, I’ll use a similar online store example

Event-Driven architectures

In an online store, suppose that after every successful order you need to do the following 4 things:

  1. Generate a PDF invoice and save it in S3/Cloud Storage

  2. Decrease the inventory in the database

  3. Send a purchase confirmation SMS/email to the user

  4. Send a message to the postal system to prepare the package

Do you think it makes sense for the user, after making their purchase, to have to wait for us to do all these things too? Absolutely not, for such a scenario we trigger an event that goes and does these things in the background by itself. You might say now, well what does this have to do with serverless at all? We can use RabbitMQ or Kafka to process these events and be done with it! Yeah, that’s right, but with this approach there are these problems:

  • Your server needs enough hardware to run the Message Broker, and if it doesn’t, you have to upgrade it
  • You have to wrestle with installing and configuring this Message Broker
  • It’s running 24 hours a day and you have to pay for the server even when you don’t have a single order throughout the month

The simpler way is serverless, meaning you only wake it up whenever you need it, let it do its job, and let it sleep.

Systems with sinusoidal traffic

Suppose it’s Black Friday and suddenly the site’s traffic shoots up and you get tons of orders The server scales without any effort and doesn’t buckle under the load. If it were a regular server, it would fall apart under the pressure. In scenarios where not a fly is flying around, as I said above, it goes to sleep and your cost becomes $0.

Personal projects and MVPs

This part isn’t very technical and is more financial. Many cloud giants have free plans for serverless, which makes it attractive for personal projects, portfolios, and MVPs. Because you don’t have to pay and you don’t have to deal with infrastructure, you get way ahead

Where can I get free serverless and get started?

At the time I’m writing this article, the free plans of the most well-known ones look like this:

  • Cloudflare:

    • Free limit: 100,000 requests per day (about 3 million per month).

    • Feature: Very high speed due to running on the Edge network, shorter execution time, and no noticeable Cold Start.

  • AWS Lambda:

    • Free limit: 1 million requests per month + 400,000 GB-seconds of processing time per month.

    • Feature: The most standard and feature-rich service in the world.

  • Google Cloud:

    • Free limit for Cloud Run, which is more for Dockerized projects: 2 million requests per month + 360,000 GB-seconds of memory and 180,000 vCPU-seconds.

    • Free limit for Cloud Functions, which like Cloudflare Workers is a type of FaaS: 2 million invocations per month.

    • Feature: Cloud Run is the best option for running Docker containers in a Serverless manner.

  • Vercel:

    • Free limit: 100 GB bandwidth + 100,000 Serverless Function executions per month.

    • Feature: The most popular option for front-end projects and frameworks like Next.js.

  • Netlify:

    • Free limit: 100 GB bandwidth + 125,000 function executions per month.

    • Feature: Excellent for deploying static projects along with Function.

This blog itself is running on Cloudflare and I’m very happy with it, both in terms of performance and how easy Cloudflare itself is to work with. I also recommend that you start with Cloudflare if you got confused reading the list above

Final note

This part was just an initial introduction. In the next parts I’ll cover the different types of serverless and we’ll learn more details together. Stay with me <3