The microservice architecture (sometimes abbreviated to microservices) is an architectural style that structures an application as a collection of services that are organized around business capabilities. It enables the continuous delivery/deployment of large, complex applications. The microservice architecture has several other benefits including better scalability, and fault tolerance. It also makes it easier for an organization to experiment with new technologies and evolve its technology stack.
The most critical architectural decision that you must make when using microservices is to identify and design the services and determine how they collaborate. In comparison, technology-related issues, such as Serverless, Docker and Kubernetes, pale into insignificance. This is the first of several posts that explores the nature of a service.
A service has several key characteristics:
The following diagram shows the structure of a service. It has a hexagonal architecture. The core of the service is its business logic, which is surrounded by adapters that communicate with other services and applications.
Let’s look at each part of the service.
From the perspective of its consumers, the only thing that matters about a service is its API. A service API consists of operations and published events.
There are two types of operations: commands and queries.
A command is an operation that mutates data.
A query is a command that retrieves data.
For example, in the FTGO application, which is my book’s example application, the
Order Service, implements commands, such as
cancelOrder(), and queries, such as
A service’s operations are invoked using some combination of synchronous protocols, such as REST or gRPC, and asynchronous messaging. Synchronous protocols, especially REST, are particularly useful when implementing APIs for external clients, such as mobile applications and Single Page applications.
However, asynchronous protocols are typically needed when implementing sagas, which maintain data consistency between services.
For example, the FTGO
createOrder() operation is implemented by the
POST /orders REST endpoint and initiates the
Create Order Saga, which is implemented using asynchronous messaging.
A service often publishes events. An event is typically DDD domain events, which are emitted by an aggregate when it’s created, updated or deleted. A service publishes events to a message channel implemented by a message broker. The Eventuate Tram framework, for example, supports publishing events to Apache Kafka, ActiveMQ and RabbitMQ.
The heart of the service and the reason for its existence. It implements the API’s operations and publishes events. The business logic invokes the operations of other services and subscribes to their events. It persists data in the service’s database.
When services collaborate, it’s through APIs rather than via the database.
A service might invoke the operations of another service.
Order Service, for example, asynchronously invokes the
Kitchen Service services.
A service can also subscribe to the events published by another service.
Order Service, for example, subscribes to events published by the
A service usually has a database, which stores its data and sometimes data replicated from other services.
For example, the FTGO
Order Service’s database stores
Orders as well as
Restaurants, which are replicated from the
In order to ensure loose coupling, it’s generally a bad idea for services to share database tables.
Instead, services must only communicate through their APIs.
In later posts, I’ll dig deeper into the nature of a service.
Microservices.io is brought to you by Chris Richardson. Experienced software architect, author of POJOs in Action, the creator of the original CloudFoundry.com, and the author of Microservices patterns.
Chris helps clients around the world adopt the microservice architecture through consulting engagements, and training workshops.
Chris teaches comprehensive workshops for architects and developers that will enable your organization use microservices effectively.
Avoid the pitfalls of adopting microservices and learn essential topics, such as service decomposition and design and how to refactor a monolith to microservices.Learn more
Chris offers numerous other resources for learning the microservice architecture.
Want to see an example? Check out Chris Richardson's example applications. See code
Got a specific microservice architecture-related question? For example:
Consider signing up for a two hour, highly focussed, consulting session.
My virtual bootcamp, distributed data patterns in a microservice architecture, is now open for enrollment!
It covers the key distributed data management patterns including Saga, API Composition, and CQRS.
It consists of video lectures, code labs, and a weekly ask-me-anything video conference repeated in multiple timezones.
The regular price is $395/person but use coupon MECNPWNR to sign up for $120 (valid until May 16th, 2023). There are deeper discounts for buying multiple seats.
Take a look at my Manning LiveProject that teaches you how to develop a service template and microservice chassis.
Engage Chris to create a microservices adoption roadmap and help you define your microservice architecture,
Use the Eventuate.io platform to tackle distributed data management challenges in your microservices architecture.
Eventuate is Chris's latest startup. It makes it easy to use the Saga pattern to manage transactions and the CQRS pattern to implement queries.
Engage Chris to conduct an architectural assessment.
Note: tagging is work-in-process
anti-patterns · application api · application architecture · architecting · architecture documentation · assemblage · beer · containers · dark energy and dark matter · deployment · design-time coupling · development · devops · docker · eventuate platform · glossary · hexagonal architecture · implementing commands · implementing queries · inter-service communication · kubernetes · loose coupling · microservice architecture · microservice chassis · microservices adoption · microservicesio updates · multi-architecture docker images · observability · pattern · refactoring to microservices · resilience · sagas · security · service api · service collaboration · service design · service discovery · service granularity · service template · software delivery metrics · success triangle · tacos · team topologies · transaction management · transactional messaging