serverless in front-end

There is a high increase of serverless applications these days to handle business logic. This is mainly a paradigm shift from manually having to deploy, update and scale the resources to use within an application to depending on third-party cloud service providers to handle most of the management of these resources. But why this trend has grown? Because for the best performance every organization wants to build a market fit application within a very short span of time. For this, their focus should be on delivering core applications instead of spending time on configurations, deployment, or testing-related activities. That is why it is essential that the business logic of the application must be handled in a serverless manner. Now before we discuss how that happens let’s understand what is serverless application is.

What is Serverless application?

Traditionally when we develop an application post-development, we need to deploy that on the servers. This has two aspects of expenses. CAPEX is initial expenses for capacity planning, installation of server software and hardware, procurement, etc. And the second one is the OPEX, which is running expenses. With Cloud implementation, such problems are solved to some extent. Still, there remains this cost burden. There comes a Serverless computing concept that abstracts users away from these infrastructure overheads and dealing with low-level configuration aspects.

To explain more, Serverless computing is a cloud execution model in which a cloud provider dynamically allocates compute resources and storage for a particular piece of code and then charges the user for it. Hence, it is not like there is no server included in the whole process, but their provisioning and maintenance burden is not on the user and is entirely taken care of by the provider.

Furthermore, this is an event-driven design and development paradigm which means the code is invoked when there is a request triggered for it. Also, users only pay for the services they are using instead of paying a flat monthly fee. No cost is associated here with downtime or idle time. Here server is not eliminated but resource considerations are moved into the background as per the design process.

Thus, with the Serverless computing concept, the CAPEX and OPEX cost decreases significantly due to fewer deployment times and fewer resource involvement. This enables developers to build complex systems quickly as different services are combined and composed in a loose orchestration. AWS Lambda is an example of public cloud Serverless computing.

So, in Serverless computing, the user uploads a function, specifies the required resources, and uploads the Cloud function. Then the Cloud vendor (Amazon, Microsoft, Google) does the server’s provisioning and deploys its function. So, the user doesn’t need to think about the server, or everything that happens in a Serverless way. Provisioning and decommissioning of servers are performed by the cloud vendors based on the demand for functions goes up and down. All of this is transparent to the end-user.

Serverless architecture consist of two different concepts –

1.Function as a Service (FaaS)

FaaS works on an event-driven basis. Also, it performs as a long-running asynchronous task via Serverless architectures. In this case, server-side logic is written by the application developer. However, unlike traditional architectures, it’s run in stateless compute containers that are event-triggered and fully managed by a third party. AWS Lambda is one of the examples of FaaS.

Furthermore, FaaS offerings do not depend on a specific framework or library for its coding. Instead, FaaS functions are regular applications regarding the language and environment. For instance, you can implement AWS Lambda functions in Javascript, Go, Python, or any JVM language like Java, Scala, Clojure, etc., or any .NET language. However, your Lambda function can also execute another process bundled with its deployment artifact, so you can actually use any language that can compile down to a Unix process.

2. Backend as a Service (BaaS)

In the case of Backend as a Service, the client application directly interacts with the data layer through an authentication layer. Here no custom logic is written on the server-side. Instead, it is solely on the client.

How Serverless is used in front-end application development

Front ends in modern application center either on a broker or on an API gateway. This broker element presents a series of APIs which we invoke either from mobile applications or from web pages. Furthermore, these APIs either connect to web servers or webpages directly invoke them via the programming language, like JavaScript. Software components work behind the APIs, which are hosted in the cloud or in the data center.

Such a front-end cloud computing model has already got modernization pressure. And there comes the microservices usage which is used for the leading edge in application front-end design. These microservices are small stateless components of logic that can scale or get replaced dynamically. Serverless is an architecture for applications that only consumes resources when it executes code, such as these microservices.

The combination of microservice and serverless approach makes the front end fully scalable and resilient to failures. This strategy eliminates the need for server management and you only need to pay for the usage of cloud hosting.

Microservice and serverless designs are event-based, however, other application designs are built around transactions. When designing cloud front ends for microservices and serverless, developers must think of transactions in relation to events.

A transaction is a multi-step process where the steps correspond to events. Each event must go into the transactional context somewhere. With microservices and serverless developers can dissect a transaction into events at the source – whereas the source could be a mobile device or the webserver.

The API gateway model suits serverless implementation. The gateway can invoke the proper serverless code based on a call from the front-end web server or mobile app. The front end can also access an online database. This access then triggers a serverless workflow. Applications built on this model, for example, access a database for order creation, then trigger a serverless workflow to transfer the processed order to the back-end application for inventory management.

Some application front ends are rich, more like a distributed processing function than a simple event handler. In these designs, cloud developers can use workflow orchestration tools — such as AWS Step Functions or Microsoft Azure’s Durable Functions — to build complex multiserverless-function workflows. These workflows resemble traditional application logic, except that they are decomposed into microservices to maximize cloud value.

State control is an important consideration for front-end applications when building serverless applications, particularly if the application might switch to more conventional cloud-native hosting in containers. As microservice or serverless function is stateless, it can’t store information between activations, which is what makes it suitable for on-demand activation, scaling, and replacement. Thus, applications that involve multiple steps with context that must be remembered have to provide state control.

Final Words:

Cloud front end is defined with microservices and stateless execution and not serverless. The serverless hosting model is suitable for many applications, but many applications are more cost-effective, and even perform better, when they’re executed another way. If you map out workflows in advance, you can spot applications where the cost and performance could be affected by serverless hosting. So, decide whether you will go for or serverless or not wisely because it may not be the best thing always.

Leave a comment