Overview on Microservices — part 1
I recently read ‘Building Microservices’ by Sam, Newman. Great insight into architecting services in our current world where the ability to rapidly adapt new technologies and deliver high-quality changes quickly are paramount. Below are some of the highlights from the book:
Because microservices are primarily modeled around business domains, they avoid the problems of traditional tiered architectures.
Domain-driven design. Continuous delivery. On-demand virtualization. Infrastructure automation. Small autonomous teams. Systems at scale. Microservices have emerged from this world.
Many organizations have found that by embracing fine-grained, microservice architectures, they can deliver software faster and embrace newer technologies. Microservices give us significantly more freedom to react and make different decisions, allowing us to respond faster to the inevitable change that impacts all of us.
What Are Microservices? Microservices are small, autonomous services that work together. Let’s break that definition down a bit and consider the characteristics that make microservices different.
Single Responsibility Principle reinforces cohesion, which states “Gather together those things that change for the same reason, and separate those things that change for different reasons.”
Jon Eaves at RealEstate.com.au in Australia characterizes a microservice as something that could be rewritten in two weeks, a rule of thumb that makes sense for his particular context.
All communication between the services themselves are via network calls, to enforce separation between the services and avoid the perils of tight coupling.
These services need to be able to change independently of each other, and be deployed by themselves without requiring consumers to change.
The golden rule: can you make a change to a service and deploy it by itself without changing anything else?
Key Benefits: Technology Heterogeneity: For example, for a social network, we might store our users’ interactions in a graph-oriented database to reflect the highly interconnected nature of a social graph, but perhaps the posts the users make could be stored in a document-oriented data store, giving rise to a heterogeneous architecture
Ability to pick a service that is perhaps lowest risk and use the technology there, knowing that we can limit any potential negative impact. Many organizations find this ability to more quickly absorb new technologies to be a real advantage for them.
Resilience: with microservices, we can build systems that handle the total failure of services and degrade functionality accordingly.
Scaling: When embracing on-demand provisioning systems like those provided by Amazon Web Services, we can even apply this scaling on demand for those pieces that need it. This allows us to control our costs more effectively.
Ease of Deployment: With microservices, we can make a change to a single service and deploy it independently of the rest of the system. This allows us to get our code deployed faster. If a problem does occur, it can be isolated quickly to an individual service, making fast rollback easy to achieve.
Organizational Alignment: Microservices allow us to better align our architecture to our organization, helping us minimize the number of people working on any one codebase to hit the sweet spot of team size and productivity.
Composability: With microservices, think of us opening up seams in our system that are addressable by outside parties. As circumstances change, we can build things in different ways. With a monolithic application, I often have one coarse-grained seam that can be used from the outside. If I want to break that up to get something more useful, I’ll need a hammer!
Optimizing for Replaceability: Teams using microservice approaches are comfortable with completely rewriting services when required, and just killing a service when it is no longer needed. When a codebase is just a few hundred lines long, it is difficult for people to become emotionally attached to it, and the cost of replacing it is pretty small.
What about SOA? The microservice approach has emerged from real-world use, taking our better understanding of systems and architecture to do SOA well. So you should instead think of microservices as a specific approach for SOA in the same way that XP or Scrum are specific approaches for Agile software development.
Why not use shared libraries instead to organize and share? First, you lose true technology heterogeneity. The library typically has to be in the same language, or at the very least run on the same platform. Second, the ease with which you can scale parts of your system independently from each other is curtailed. Next, unless you’re using dynamically linked libraries, you cannot deploy a new library without redeploying the entire process, so your ability to deploy changes in isolation is reduced. And perhaps the kicker is that you lack the obvious seams around which to erect architectural safety measures to ensure system resiliency.
COPYRIGHT Newman, Sam (2015–02–02). Building Microservices. O’Reilly Media.