.NET Core-based Microservices with Serverless capabilities
Written by Syed Usman Chishti
Technical Content Writer
June 5, 2023
In today’s fast-paced world, companies must adopt technology that helps them to meet customer demands faster and more efficiently. A .NET Core-based Microservices architecture is a design pattern that allows the development of complex applications as a suite of small, independent services. These services can be developed and deployed independently, which makes them easier to manage, scale, and maintain.
Additionally, serverless computing is an innovative approach to building and running applications without worrying about the underlying infrastructure. In this case study, we will compare .NET Core-based microservices with serverless to .NET framework with Web API to determine which is better for developing modern applications.
Problem Statement
A multinational company wants to create a web application that allows users to buy and sell products online. The company has a web application developed using the .NET framework with Web API. However, the application faces challenges like scalability, agility, and maintenance due to its monolithic architecture. Therefore, the company wants to implement microservices architecture to improve scalability and agility. Therefore, they are considering using .NET Core with microservices and serverless computing.
- Cross-platform compatibility: .NET Core is cross-platform and runs on Windows, Linux, and macOS. This makes it easier to develop and deploy applications on multiple platforms.
- Open source: .NET Core-based Microservice is open, meaning developers can modify and extend the source code to suit their needs. This also means that the community can more quickly resolve bugs and issues.
- Lightweight and modular: .NET Core is designed to be lightweight and modular, allowing developers only to include the necessary components. This results in smaller application sizes and faster startup times.
- Better performance: .NET Core is faster and more efficient than .NET Framework, especially for web applications. It uses a new runtime called CoreCLR, optimized for modern hardware.
- Improved security: .NET Core has several security features built-in, such as data protection, HTTPS enforcement, and cross-site scripting (XSS) protection.
- Better support for containers: .NET Core has better support for containers than .NET Framework, making deploying applications to container platforms like Docker easier.
.NET Core provides a more modern, flexible, and performant platform for building and deploying applications. However, it may not be suitable for all scenarios, primarily if you work with legacy applications or technologies that only work with .NET Framework.
Benefits of Microservice Architecture over Monolithic
- Scalability: Microservices allow individual components of an application to be scaled independently of one another. This means that if one service is experiencing high traffic, it can be scaled up without scaling the entire application.
- Flexibility: Microservices allow for greater flexibility in technology choices. Different services can be written in different programming languages or use different databases, depending on their specific needs.
- Resilience: If a single service fails in a monolithic architecture, it can bring down the entire application. In a microservices architecture, however, a failure in one service does not necessarily affect the entire application, as other services can continue to function.
- Agility: Microservices allow for faster development cycles and easier deployment of updates. Small, self-contained services can be updated and released independently without affecting other parts of the application.
- Improved collaboration: Microservices encourage better collaboration between teams. Each service can be owned by a separate team, focusing on developing and maintaining that service without interfering with other teams.
Microservices offer greater flexibility, scalability, resilience, and agility than monolithic architectures. However, it’s important to note that microservices also introduce additional complexity and require careful planning and management to ensure they are implemented effectively.
Benefits of Serverless over PaaS
- Reduced costs: In a PaaS model, you typically pay for the entire runtime environment, even if your application does not use all the resources. With serverless, you only pay for your application’s exact computing resources.
- Increased scalability: While PaaS can scale up and down based on demand, it still requires manual configuration to manage the resources. On the other hand, serverless can automatically scale up or down based on the exact number of requests and the amount of processing required.
- Higher availability: With PaaS, if the underlying infrastructure experiences an issue, it can affect the availability of your application. Serverless providers, however, often have built-in redundancy and failover mechanisms that help ensure high availability.
- Faster development and deployment: With serverless, developers can focus on writing code instead of managing infrastructure. Serverless providers handle tasks like scaling, monitoring, and maintenance, allowing for faster application development and deployment.
- Lower maintenance burden: With PaaS, you still need to manage some aspects of the infrastructure, such as security updates and patching. With serverless, however, these tasks are often handled by the provider, reducing the development team’s maintenance burden.
Overall, serverless computing offers many benefits over PaaS, including reduced costs, increased scalability, higher availability, faster development and deployment, and lower maintenance burden. However, it’s important to note that serverless may only be the best fit for some applications, and it’s essential to carefully evaluate your needs before deciding.
The most prominent benefits organizations will gain after adopting serverless.
Image courtesy of OReilly.com
Microservice Architecture with Serverless Diagram
API Gateway
Azure API Gateway is a cloud-based service provided by Microsoft Azure that enables developers to create, manage, and secure APIs (Application Programming Interfaces) for their applications.
API Gateway acts as a front door for backend services, allowing developers to expose their APIs to external clients, such as web or mobile applications, and manage traffic to their APIs by controlling access, rate-limiting requests, and performing transformations on incoming and outgoing data.
With Azure API Gateway, developers can add custom authentication and authorization mechanisms, such as OAuth or API keys, to ensure secure access to their APIs. Additionally, API Gateway provides analytics and monitoring capabilities to track API usage, errors, and performance metrics.
In summary, Azure API Gateway is a powerful tool for managing APIs in the cloud, providing developers with a central point of control to manage and secure their API services.
Function App
Function App is nothing but a collection of functions, and each function represents an HTTP call. In our case, we have User Account Function App. It will have all functions related to the User, and the trigger of those functions will be an HTTP call that, which means those will be available over a URL
For example:
Azure-function-app/user/create-user
Azure-function-app/user/1
According to Microservice Architecture, applications should be divided into functional modules, and each module should have its database. Here in our case, User Account is a functional module, and it has its database UserDB.
How to Create Function App
Open Visual Studio, Navigate to Create New Project, and select Azure Functions shown in the picture
Select Http Trigger from the left panel to call this function with the URL and provide the Function name that will be the Function App name.
After you click on Continue, you’ll be prompted with the below dialog. Insert the project name and click Create.
The below picture shows the structure of the project that we just created, and we can add more functions to this project that will be used for User Account management.
When we deploy this function app to Azure, we’ll get a public URL that consumers will use.
However, we must repeat the same steps to create Function Apps for Inventory and Shipping.
Note: User Account, Inventory, and Shipping projects will be independent of each other; these should not be part of the same solution. Every project should live in its Solution, and all dependencies must adhere to Microservice Architecture.
Results
The company implemented the application using .NET Core-based microservices and serverless computing. The following are the key results:
- Scalability: The application can now manage the growing user traffic without any performance degradation. The company could oversee ten times more users with the new architecture.
- Agility: The company released new features and functionalities faster than before. The time-to-market was reduced by 50%, which helped to increase the revenue.
- Maintenance: The application is easier to maintain now, and the company reduced the number of bugs and errors by 40%. The developers can now focus on developing new features and functionalities rather than fixing bugs.
Conclusion
In conclusion, the .NET Core-based microservices and serverless computing is a better approach than the .NET framework with Web API for developing modern applications. The microservices architecture allows for better scalability, agility, and maintenance, while serverless computing reduces the operational overhead. By adopting this approach, companies can develop applications faster and deliver value to their customers more efficiently. This case study demonstrates the benefits of this approach in overcoming the challenges faced by the company in its existing application. Microservices allowed for independent development, testing, and deployment of services, leading to better agility and maintenance. Serverless computing further reduced the operational overhead of managing the infrastructure, allowing the company to focus on delivering value to its customers.
Royal Cyber Full Stack developers have been building such innovative solutions for years. Our certified consultants can help you get the most out of the latest advancements in full stack. Feel free to contact our team if there are any queries.
Recent Blogs
- Learn to write effective test cases. Master best practices, templates, and tips to enhance software …Read More »
- In today’s fast-paced digital landscape, seamless data integration is crucial for businessRead More »
- Harness the power of AI with Salesforce Einstein GPT for Service Cloud. Unlock innovative ways …Read More »