Chapter 5. Create Microservices on Azure Service Fabric

This chapter deals with the exciting world of microservices and Azure Service Fabric. In this chapter, we will cover the following recipes:

  • Downloading and installing Service Fabric
  • Creating a Service Fabric application with a stateless actor service
  • Using Service Fabric Explorer

Introduction

Traditionally, developers wrote applications in a monolithic manner. This means one single executable that is broken up into components via classes and so on. Monolithic applications require a great deal of testing, and deployment is tedious due to the bulkiness of the monolithic application. Even though you might have multiple developer teams, they all need to have a solid understanding of the application as a whole.

Microservices is a technology that aims to address the issues surrounding monolithic applications and the traditional way of developing applications. With microservices, you can break the application into smaller bits (services) that can function on their own without being dependent on any of the other services. These smaller services can be stateless or stateful and are also smaller in scale in terms of functionality, making them easier to develop, test, and deploy. You can also version each microservice independently from the others. If one microservice is receiving more load than the others, you can scale only that service up to meet the demands placed on it. With monolithic applications, you would have to try and scale the whole application up in order to meet the demands for a single component within the application.

Take, for example, the workings of a popular online web store. It could consist of a shopping cart, shopper profile, order management, backend login, inventory management, billing, returns, and much more. Traditionally, a single web application is created to provide all these services. With microservices, you can isolate each service as a standalone, self-contained bit of functionality and code base. You can also dedicate a team of developers to work on a single portion of the web store. If this team is responsible for the inventory-management microservice, they would handle every aspect of it. This, for example, means everything from writing code and enhancing functionality, to testing and deployment.

Another excellent side effect of microservices is that it allows you to easily isolate any faults you might come across. Finally, you can also create microservices in any technology you want (C#, Java, VB.NET), as they are language independent.

Azure Service Fabric allows you to scale your microservices easily and increases application availability because it implements failover. When microservices are used with Fabric, microservices become a very powerful technology. Think of Azure Service Fabric as a Platform as a Service (PaaS) solution, on top of which your microservices sit. We call the collection that the microservices live on a Service Fabric cluster. Each microservice lives on a virtual machine, which is referred to as a node in the Service Fabric cluster. This Service Fabric cluster can live in the cloud or on a local machine. If a node becomes unavailable for any reason, the Service Fabric cluster will automatically redistribute the microservices to the other nodes so that the application remains available.

Finally, here is a word on the differences between stateful and stateless microservices. You are able to create a microservice as stateless or stateful. When a microservice relies on an external data store to persist data, it is stateless in nature. This simply means that the microservice does not maintain its state internally. A stateful microservice, on the other hand, maintains its own state by storing it locally on the server it resides on.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.48.204