Join Chander Dhall for an in-depth discussion in this video Stateless and stateful microservices, part of Microservices and Azure Service Fabric Basics for Developers.
- [Instructor] When do we need state? Since http is a stateless protocol, web applications are stateless by default. However, there are scenarios where we might need the identity of the current user, the current state of the session, or maybe the contents of a shopping cart. And sometimes, also the current step in a navigation flow of the application. These are some of the scenarios where we might need a solution to capture state.
Azure Service Fabric supports two kinds of microservices. They are stateless, and stateful. A stateless service is one where we do not need to capture the state. For example, if we have an image as an input, and we need the thumbnail for it. There's no real reason to capture any state of the image for future purposes. Any subsequent request to the service would be a completely different picture, and it would return the thumbnail.
Whereas, in case of a stateful service, if we have a user in the shopping cart, and he adds different products on the website. And then he moves on to different pages, before he selects another product, we need to be able to somehow retain the shopping cart. That needs to be captured in some kind of a relational, or a NoSQL database. Stateless Microservices. Here is a representation of a stateless, microservice-based architecture.
As you can see, there's a load balancer. And then we have a stateless web tier. This web tier talks to the middle tier, that talks to the database. In order to capture state, in this scenario, we will have to create our own caching mechanism. In this case, we could use Redis, Memcached, or any other second-level caching engine. In order to make it more reliable, we can use a queue. However, this is a lot of work that we have to do on our own.
So when we implement a stateless microservice, we have to think of a partition storage, a queue, a caching engine, and also maintain the state consistency on our own. The benefit of a stateful microservice, especially Azure stateful microservice, is that we don't have to do any of that. And that gets taken care of by Azure Service Fabric. So you can see, we have a load balancer, and we have a stateless web tier.
At the same time, we have a stateless middle tier, and then we have the data tier. The benefit of Azure Service Fabric is that we will only have to worry about our application. The rest will be taken care of by Azure Service Fabric. And when I say rest, I mean the state will be completely taken care of by the stateful microservice. We will see the difference when we build a stateful microservice later in the course. So with Azure Service Fabric, stateful microservice, we get a stateful tier, and we have no need for queues and caches, and we have really low latency without writing a single line of code.
- Reviewing microservices vs. monolithic architecture
- Reviewing microservices and Azure Service Fabric basics
- Programming model architecture
- Creating a stateless service and a stateful service
- Creating a cluster in Azure
- Adding security to a cluster
- Finalizing cluster creation
- Deploying to an Azure cluster
- Debugging an application remotely