The geometry of microservices - cubes, hexagons, triangles, and more

microservice architecture   success triangle   devops   team topologies   hexagonal architecture   loose coupling   design-time coupling  

One of my favorite talks on the microservice architecture is my JFokus 2020 talk Cubes, Hexagons, Triangles, and More - Understanding Microservices. It uses a series of shapes as visual metaphors to explain key microservice architecture concepts.

Let’s have a look at the first two shapes: the success triangle, which provides the motivation for using microservices, and the scale cube, which defines the microservice architecture.

Success triangle

In order to thrive in today’s crazy world, businesses need to be more nimble, more agile and innovate faster. And since most modern businesses are powered by software, IT must deliver software rapidly, frequently, and reliably as measured by the DORA metrics.

Delivering software rapidly, frequently, and reliably requires what I call the success triangle. The success triangle consists of the following elements:


Scale cube

The Monolithic architecture is suitable for many application, especially those that are small and are developed by a small number of teams. However, for larger, more complex applications that are developed by many teams, it’s often better to use the Microservice architecture. My definition of the microservice architectures corresponds to Y-axis scaling from AKF Scale Cube, which functionally decomposes an application into services.


Hexagonal architecture

The hexagonal architecture, a.k.a. ports and adapters, is a great way to structure a service. Unlike the more traditional layered architecture, the hexagonal architecture puts the business logic at the heart of the service. Inbound adapters that handle requests from the service’s clients and outbound adapters which make requests depend on the business logic.


Iceberg

An essential characteristic of the microservice architecture is loose design-time coupling. Services should rarely need to be changed in lockstep. One way to achieve loose design-time coupling is to design services so that they resemble icebergs. The API, which is the visible part of the service, should be much smaller than the invisible implementation. By keeping the implemention hidden, developers can change it without affecting clients.


Loose runtime coupling

Another essential characteristic of the microservice architecture is loose runtime coupling. Tight runtime coupling between services reduces availability and increases latency. To minimize runtime coupling, services should be self-contained. A self-contained service responds to a synchronous request without waiting for another service to respond. If necessary, it uses asynchronous messaging to complete the request. The cylinder depicts a message channel, which is how services communicate asynchronously.


Test pyramid

Even today, many organizations often rely on manual testing. Yet automated testing is essential if you want to deliver software, rapidly, frequently and reliably. Moreover, the microservice architecture simultaneously simplifies testing and also creates some challenges. The sixth and final shape is the test pyramid. The test pyramid is a visual metaphor that shows the relative proportions for the different types of tests that you need to write for a service.

The tests at the bottom of the pyramid are fast, cheap to write and reliable, while as you move up the pyramid, the tests become progressively slower, more expensive to write and less reliable. The test pyramid is consists of the following layers:

  • unit tests - fast, in-memory tests of classes or clusters of classes. If your service implements complex algorithms, you should test them thoroughly with unit tests.
  • integration tests - tests that verify that the service’s adapters work as expected. A service’s adapters are those classes that communicate with the outside world, eg. controllers, which handle HTTP requests, and repositories, which access a database. Integration tests also include consumer-driven contract tests, which verify that a service communicates correctly with its clients and dependencies.
  • component tests - tests that (unlike unit tests and integration tests, which test part of a service) verify that the service as a whole works correctly. A service’s component test might, for example, package the service as a container image, and test the running container.
  • end-to-end tests - tests that verify that the application as a whole works correctly. It’s important to remember, however, that a defining characteristic of the microservice architecture is that services are independently deployable. A service that passes the unit, integration and component tests must be production ready.

The test pyramid is not a perfect metaphor, however. You might, for example, have more integration tests than unit tests. However, a key idea is that you should push testing down the pyramid as much as possible. In particular, you should avoid end-to-end testing, at least on the path from developer laptop to production.


Want to learn more about testing microservices?

My Microservices patterns book has two chapters dedicated to testing microservices.

Need help adopting microservices?

I provide consulting and training.


microservice architecture   success triangle   devops   team topologies   hexagonal architecture   loose coupling   design-time coupling  


Copyright © 2024 Chris Richardson • All rights reserved • Supported by Kong.

About www.prc.education

www.prc.education 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.

Upcoming public workshops: Microservices and architecting for fast flow

In-person: Berlin and Milan

DevOps and Team topologies are vital for delivering the fast flow of changes that modern businesses need.

But they are insufficient. You also need an application architecture that supports fast, sustainable flow.

Learn more and register for one of my upcoming public workshops in November.

NEED HELP?

I help organizations improve agility and competitiveness through better software architecture.

Learn more about my consulting engagements, and training workshops.

LEARN about microservices

Chris offers numerous other resources for learning the microservice architecture.

Get the book: Microservices Patterns

Read Chris Richardson's book:

Example microservices applications

Want to see an example? Check out Chris Richardson's example applications. See code

Virtual bootcamp: Distributed data patterns in a microservice architecture

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 CCMHVSFB to sign up for $95 (valid until November 8th, 2024). There are deeper discounts for buying multiple seats.

Learn more

Learn how to create a service template and microservice chassis

Take a look at my Manning LiveProject that teaches you how to develop a service template and microservice chassis.

Signup for the newsletter


BUILD microservices

Ready to start using the microservice architecture?

Consulting services

Engage Chris to create a microservices adoption roadmap and help you define your microservice architecture,


The Eventuate platform

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.


Join the microservices google group