knowledge-base

« Back To Overview

Architecture Style: Microservices

Microservices Architecture Style Image

Description

Was named and use popularized by a blog post from Martin Fowler and James Lewis. The microservices style is heavily inspired on Domain-Driven-Design (DDD). The concept of Bounded Context (from DDD) was a decisive inspiration, which represents a decoupling style. The goal of microservices is high decoupling, physically modeling the logical notion of bounded context.

The driving philosophy of microservices is the notion of bounded context: each service models a domain or a workflow.

Topology

We create single-purpose services that implement a bounded context. Each service is expected to include all necessary parts to operate independently, including databases and other dependent components.

Distributed

Granularity

Data Isolation

API Layer

Operational Reuse

Microservices prefer duplication over reuse, to avoid coupling. However, some parts, like operational components (e.g. monitoring, logging, circuit breakers,…) could really benefit from coupling. Even when using distinct bounded contexts, there will be similarities, especially from operational aspect.

The Sidecar Pattern offers a solution to this problem. Reusable components can be located in this sidecar and independently maintained by other teams (e.g. Infrastructure Teams). This pattern is very popular in service mesh. This patterns creates a consistent operational interface across all microservices. This is a part of thinking about creating a “platform”.

Sidecar Diagram

Frontends

It is common to see a single (monolithic) user interface that talks to a microservice architecture. However, ideally the frontend is follows also the same design philosophy of microservices and we would expect to see micro frontends. Micro frontends exist, however due to practicalities and the novelty of the concept it is not so mainstream. However, we do expect further adoption.

Communication

Finding the correct communication channel helps keeping services decoupled, yet coordinated in a useful way.

Choreography and Orchestration

Diagrams:

Transactions and sages

Don’t do transactions in microservices, fix granularity instead! See the “Granularity”. However, exceptions do exist, when they do, patterns exists with serious trade-offs.

A popular distributed transactional pattern in microservices is the saga pattern. In this pattern a service acts a service using the mediator/orchestration pattern. The drawback on this is, when a single step in the transaction fails, all previous steps must be informed to cancel the step or execute a compensating action.

This style of transactional coordination is called Compensating Transaction Framework. The complexity of this and all challenges to implement this (especially undo actions) makes it less than desirable. Where possible, try to avoid cross service transactions all together and rethink your bounded contexts.

Diagrams:

Nuggets Of Wisdom

The best way to think about microservices is not by defining the size, but rather by determining the purpose.

When To Use

When NOT To Use

Considerations

Characteristics

Characteristic Rating
Partitioning Type Domain
Number of quanta One to many
Deployability ⭐⭐⭐⭐
Elasticity ⭐⭐⭐⭐⭐
Evolutionary ⭐⭐⭐⭐⭐
Fault Tolerance ⭐⭐⭐⭐
Modularity ⭐⭐⭐⭐⭐
Overall cost
Performance ⭐⭐
Reliability ⭐⭐⭐⭐
Scalability ⭐⭐⭐⭐⭐
Simplicity
Testability ⭐⭐⭐⭐

Resources