7

I was wondering how the hexagonal architecture relates to microservices. Do the microservices all go into the core of the hexagon? Or does each microservice get a hexagonal architecture? Or is it both (fractal)?

2 Answers2

7

Hexagonal architecture is applied to one microservice.

And if you are using DDD:

  • At strategic level, each microservice would be a bounded context.

  • At tactic level, inside each microservice, the hexagon would enclose the application layer and the domain model. The adapters would be the infrastructure layer.

choquero70
  • 3,332
  • 2
  • 24
  • 40
2

Do the microservices all go into the core of the hexagon?

A microservice is an entire service, if it was the inside the hexagon it would mean you cannot have any adapters inside so no way to expose your business logic on the network. So the business logic of a microservice is constrained to the inside of the hexagon, and all the technical layers, like your Rest Controllers, your persistence layer, your clients stay in adapters outside of your hexagon. You can check out this article on the hexagonal architecture.

does each microservice get a hexagonal architecture?

Yes and No. As Choquero70 said, in DDD/Hexagonal Architecture a microservice is sized after a bounded context. Let's say a single subdomain responsibility of the business of your platform e.g. billing, shipping, catalog for an e-commerce website. In that case a microservice can be built with the hexagonal architecture.

But sometimes you need to develop technical microservices for mappings, integration whatever. If a microservice is not dealing with business logic, it might be painful to use the hexagonal architecture, you'll end up with a lot of intermediary mappings to isolate a business responsibility which doesn't exist anyway.

Simeon Leyzerzon
  • 17,374
  • 7
  • 44
  • 68