From the course: DevOps Foundations: Microservices
What are microservices?
From the course: DevOps Foundations: Microservices
What are microservices?
To understand how microservice architectures are different from other architectures, such as monolithic, we need to look at a bit of application architecture and design. Let's start with the simplest definition possible. Microservices are little mini programs that make up a larger system. Instead of trying to do lots of things, a microservice focuses on one very specific area of a system. Microservices deconstruct traditional services according to a software design practice called domain driven design. Using domain driven design, components of a system are organized around a business domain. Application architects use a domain model to represent the application architecture of a system. A domain model is a representation of the entities within a domain, using business terms as names for those entities. Let's look at some examples. Suppose you're writing a banking application or a real estate application or a healthcare application. Your domains are banking, real estate, and healthcare, respectively. The entities of each model might include: For banking, we could have account holder, account transaction, and a loan. For real estate, we might have a buyer, a seller, some generic term for a real estate like a parcel, which could be a building or just land, and let's say a sale contract. For health care, we might have a patient, a provider, a doctor, an encounter, which could be a visit, a prescription and an insurance code. This is by no means an exhaustive list, but it serves to demonstrate some examples. These entities are named using business terms that a loan officer or a real estate agent, or a doctor or nurse would recognize. Each entity has attributes that are used by an application to perform its function. If you're familiar with object-oriented design, this representation should look very familiar. Now we can compare services and microservices. Let's take the banking domain as an example. In a traditional approach, we'd write services to handle data and business logic for all these entities. We'd pack them together in a single binary and deploy them. We have a distributed monolith, their services, but all these entities are tightly bound together and implemented as a single deployable. They can't be deployed independently of each other. Microservices, however, are not monolithic because each microservice handles only a single entity. The micro in microservices refers to this lean and mean implementation instead of being a big, bulky binary, each microservice includes only the code it needs to implement the data and logic of a single entity. Bounded contexts are used to group elements of a domain model. It's helpful to think of a bounded context like a taxonomy. It's a grouping of elements that have some common features and data. If you're familiar with a programming language like Java or C-sharp, you can think of a bounded context as similar to a namespace. The goal of bounded contexts is to ensure that every name of every entity has a clear, unambiguous definition. Microservices take advantage of this approach to draw clear, practical lines between two microservices that handle different contexts. The concentration of a single context in microservices also follows the single responsibility principle, one of the solid design principles in object-oriented design. This concept can be applied to microservices as well as objects. The single responsibility principle states that every class should have only one reason to change. We can apply the same general idea to microservice design. Each microservice should have one clearly defined job to fetch, commit, and apply business logic and validation logic to data within a single context. Any behavior that falls outside of this definition should be implemented in a separate service. Here's an example. The microservice that supports an orders data context should not have code in it that implements behaviors from other contexts like inventory, account, customer, or any other. The orders microservice does exactly one thing: Provide fetch and commit access to data in the dedicated orders database. That's it. Here's what the deployment looks like when we break each of these entities into a set of microservices. This architecture benefits from the additional loose coupling provided by splitting each entity into its own service. Development teams can now work on each microservice separately and in parallel. Development, testing, and deployment of each microservice can proceed independently of the others as long as the interfaces of the microservices remain unchanged. This has an even greater impact on velocity, especially when combined with DevOps practices. Let's move on and learn more.