Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How Does a Serverless App Work?

DZone's Guide to

How Does a Serverless App Work?

While you might have played around with AWS Lambda, let's see how serverless architectures actually work and what benefits and drawbacks they offer to monoliths.

· Cloud Zone ·
Free Resource

Site24x7 - Full stack It Infrastructure Monitoring from the cloud. Sign up for free trial.

Serverless might look like a bright, sunny day but it isn’t that sunny after all. It has brought about a big difference when it comes to application architecture.

Moreover, the change with serverless isn’t gradual, but a jolt. FaaS drives a totally different type of application architecture through a fundamentally event-driven model, a much more granular form of deployment.

So:

  • How does a serverless app actually work?
  • What does serverless architecture look like?
  • How is it different from monolithic architecture?

These are the questions that we’re going to tackle in this article. Let’s dive deeper and understand serverless architecture and its workings.

Reference Application

Let’s make some assumptions about our reference application.

  • It is a multi-user app.
  • It has a mobile-friendly user interface.
  • User management and authentication are required.

We’ve certainly overlooked some other features that you might expect in a basic app, but the point of this exercise is not to actually build an app — only to compare a serverless application's architecture with a legacy, monolithic architecture.

Monolithic Architecture

Given those requirements, a monolithic architecture for our app might look something like the figure below:

serverless architecture

  • A native mobile app for iOS or Android
  • A backend is written in Java and HTML
  • A relational database

In this architecture, a mobile app is responsible for handling the app interface and input from the user, but it delegates most actual logic to the backend. From the perspective of our code, the mobile app is lightweight and quite simple. It uses HTTP to make a request to multiple API endpoints served by the Java backend.

Authentication and user management are encapsulated with the Java application code. Moreover, it also interacts with the relational database in order to store user data.

Why Change?

You might say, “I am perfectly fine with this architecture as it meets all my requirements, so why just not stop there and call it a day?”

To which I will reply that there are multiple challenges and operational pitfalls that I will discuss in this section to which you might relate. Go on!

In building this app, you’ll need to have hands-on expertise in iOS and Java, don’t you? Apart from that, you need to have good experience in configuring, deploying, and operating Java application servers as well as a relational database. Moreover, think about their host systems, whether container-based or running directly on virtual or physical hardware?

We’ve not yet touched scalability, security, or high availability, all of which are critical aspects of the modern production system. The bottom line is that all these complexities, at one point in time, will create friction when you are be fixing bugs, adding features, or trying to rapidly prototype new ideas.

And hence, you need a change!

Serverless Architecture

A serverless architecture of our basic application would look something like the figure below:

serverless architecture

According to this architecture, while the user interface will still remain a part of the native mobile app, user authentication and management will be handled by a BaaS service like AWS Cognito. These services can be called directly from the mobile app to handle user-facing tasks like registration and authentication.

Moreover, the same BaaS can be used by other backend components to retrieve user information.

With user management and authentication now handled by the BaaS, the logic that was previously handled by the backend Java application is simplified. You can use another amazing serverless component, AWS API Gateway, to handle routing HTTP requests between a mobile app and your backend in a secure and scalable manner.

Each distinct operation can be encapsulated in a function. A FaaS platform such as AWS Lambda takes each of these functions and runs them in parallel ‘containers’ that can be monitored and scaled separately.

Those backend FaaS functions can interact seamlessly with a NoSQL BaaS database like AWS DynamoDB. In fact, one drastic change is that we no longer store any session state within our server-side application code, and instead will persist in our NoSQL storage.

While it may seem to you like a minute change, believe me, it will help you significantly with scaling.

What Got Better?

You might say, “There is no significant difference in terms of complexity, and it has, in fact, more specific application components that our traditional monolithic architecture?”

To which I will reply that the code you will write now will be solely focused on the logic of the app. What’s more? Our components are now decoupled and separate. Due to that, we can switch them or add new logic very fast without the inherent friction present in a monolithic architecture.

Scaling, high availability, and security are the areas all backed up with our serverless architecture. This means that as the popularity of your app grows, you needn’t worry about renting more powerful servers, or failure in a database, or troubleshooting a firewall configuration.

In short, labor cost has reduced, as well as the risk and resources cost of running it. All of its constituent components will scale flexibly. What else? If you have an idea for a new feature, our lead time is highly decreased, hence, we can start getting feedback and working on it efficiently.

Pretty exciting, right?

Conclusion

The aim of this blog is to clear the confusing clouds over the minds of people who are not sure about how serverless apps work!

Serverless systems are still in their infancy, and it will be wonderful to witness how they solve and fit into our architectural requirements.

Site24x7 - Full stack It Infrastructure Monitoring from the cloud. Sign up for free trial.

Topics:
serverless architecture ,serverless functions ,cloud ,monolithic architecture ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}