Serverless Architecture With Azure Functions: An In-depth Guide

What is Azure serverless architecture? Let's discover further details about azure functions architecture diagram and azure serverless functions tutorial. 

Serverless Architecture With Azure Functions | Relia Software

As a web application developer, you are probably quite familiar with the Front-end – Back end (Client – Server) model. In this model, Front-end is installed on the client side, Back end is installed on the server.

The picture below is the traditional model that is still commonly used:

traditional-model-frontend-backend.png
Traditional Technical Architecture (Source: Internet)

With the above architectural model, when deploying, the developer needs to set up a server including a Web server and a database server, which can lead to the following limitations:

  • Difficulty in deploying and setting up the server.
  • Expensive server maintenance costs.

However, today as cloud computing services develop, there is a new approach to solve the above problem: using Serverless architecture.

What is Serverless?

In the client-server model, you need to rent or buy a server to deploy your application. But for Serverless computing, you will not need to care about this. Just register the service with the provider, they will provide and manage resources for you. You just need to write code and don't need to worry about deployment or infrastructure to run the application.

Serverless has 2 main services:

Backend as Service (BaaS)

>> Read more about: What is .NET? Empowering Cross-Platform Development

With BaaS, instead of having to write code on the backend (Java, .NET), you will use 3rd party APIs to perform logical processing on the server. There are many 3rd parties that provide this service such as Parse, Firebase and AWS Cognito... This method is quite convenient because it reduces the effort of writing backend code but has the disadvantage of being heavily dependent on 3rd parties.

backend-as-a-service.jpg
Backend as Service (BaaS) (Source: Internet)

Function as Service (FaaS)

In this model, you will have to write code in the backend, but instead of deploying to the server, you deploy as a function. So this way you will be more proactive in the backend and don't need to care about the server. This function will be called as RestAPI, you will pay according to the number of calls to your function.

FaaS services are quite famous because of Amazon.

faas-function-as-a-service.jpg
Function as Service (FaaS) (Source: Internet)

Advantages and disadvantages of serverless

However, any system has its own strengths and weaknesses. The same goes for Serverless architecture.

Advantages

Lower cost

You do not need to spend management costs on server maintenance, the service provider will charge you according to the number of function calls.

>> You may consider: How Much Does It Cost To Design an App?

Scalability

Just like cloud services, when the number of requests increases, the system will automatically create additional processes when there are many requests. You do not need to invest in upgrading the server like the traditional client-server model.

More time for user experience

Users do not need to care about building a server, just focus on coding, everything else will be taken care of by the service provider.

Disadvantages

Security

To use resources effectively, service providers can install applications from many different customers on the same physical server. That poses a potential security risk, if your application works with important data.

Performance

Serverless does not work well for long-running applications. A request on serverless will take more time than running on a private server.

Vendor lock-in

Your application depends entirely on the service provider, so you do not have full control over your application and will have difficulty debugging.

Instructions for deploying applications with Azure Functions

This section will introduce a specific case study about Serverless Architecture.

Microsoft Azure Function is quite a famous Function as a service from Microsoft, allowing to run your code on the server, supporting C#, JavaScript,...

Sign up for the service

You need to register for a Microsoft account, Azure function allows developers to try the service. Azure functions provide several scenarios and programming languages for developers to choose from

In this case choose Webhook + API and programming language is C# or JavaScript → Create this function. Microsoft will setup and deploy the server for you.

Sign up for the service
Sign up for the service (Source: Internet)

Create function

Click the + button to create a function.

Create-function.png
Click the + button to create a function (Source: Internet)

Azure provides several languages such as C#, JavScript and a number of scenarios for you to choose from. In this case, you can choose HttpTrigger, this function is run when there is an HttpRequest

Naming-the-function.png
Naming the function (Source: Internet)

Naming the function GetCurrentDateTime, we will write a simple Azure function that returns the current time.

Start coding

csharp
using System.Net;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)

{

   await Task.Yield();

   log.Info("C# HTTP trigger function processed a request.");

   string currentTime = DateTime.Now.ToString("h:mm:ss tt");

   return currentTime == null

       ? req.CreateResponse(HttpStatusCode.BadRequest, "Can not get current time")

: req.CreateResponse(HttpStatusCode.OK, "Current Time is " + currentTime);

   }

Then select Get Function URL to get the link.

the-request-URL-you-will-use-to-call-from-your-application.png
Then select Get Function URL to get the link (Source: Internet)

This link is the request URL you will use to call from your application.

the request URL you will use to call from your application
This link is the request URL you will use to call from your application. (Source: Internet)

Test function

Now you can test your Azure Function. The most convenient way is to use the Chrome add-in tool PostMan.

Copy the link into PostMan and press the Send button to get the result → done

Test-function.png
Copy the link into PostMan (Source: Internet)

Conclusion

Through the example above, you can see that using Serverless architecture makes deploying source code very simple and saves time. Developers only need to focus on writing code and do not need to care about setup and deployment on the server.

Although there are some limitations, Serverless will be a new technology trend in the future.

>>> Follow and Contact Relia Software for more information!

  • coding
  • development