Serverless computing is an example of PaaS (Platform as a Service) services. The idea of the serverless approach is that the service provider, without the user's involvement, controls and configures the operation of physical infrastructure, virtual machines, storage systems, and the environment to run the client’s code.
The user also gets automatic scaling and fault tolerance. Serverless services are designed so that your code runs even in the case of a fault of one or even several data centers. If your code is called more frequently over time, the service will take on the task of scaling the infrastructure on which the code will run.
Let's consider an example of a company that rents electrical scooters. Within its system, telemetry from rental stations needs to be collected. In practice, stations may fail, and over time their count will increase. This means that the traffic from stations will always be different. The amount of data will be sometimes large, sometimes small, but on average it will increase over time. When using serverless functions, the system will react to all these changes automatically and call fewer or more functions depending on the volume of traffic. The company does not need to do anything for this - everything will happen automatically.
The company will not have to worry even about server failures because the internal structure of the functions is tolerant to this. The company can be confident that its system will adapt to changes in the flow of data, and all data will be processed. When using IaaS, a lot of tasks like adjusting the system to changing loads, handling software errors, or hardware failures would fall on the company's employees.
The concept of serverless computing is useful when you need to quickly create a REST API, write a chatbot, process a message queue, process data from a device, etc. The approach allows you to not worry about virtual machines, operating systems, runtime settings, scaling, and fault tolerance - all tasks are solved by the service. At the same time, the solution is cheaper than using virtual machines, because you pay only for the time your code runs.
However, the concept imposes two important restrictions on the user's code:
- The function must have time limits. It cannot be designed for infinite work in a loop.
- The function cannot store states between runs. Each time the function is launched, it will have no information about the previous work.
is a classic example of serverless, combining all the advantages of this approach.