0

I've been struggling for a while of what would be the "recommended" approach for a microservice itself.

There are quite of top architecture designs that are the holy sacred for a lot of craftsman devs, such as CQRS, Hexagonal, DDD, etc...

But from my point of view, depending of how "big" is the microservice, because you know the word itself it's giving you a hint... "micro"!!

Should I consider build all the packages, interfaces, divisions between layers such as Hexagonal, or split the content of the microservice based on DDD (its supposed that 1 microservice its 1 domain??? if not... :| kind of WTF??)

Or just keep it on its essence like split the entrypoints(rest,queues)-core(business logic)-outpoints(DB,queues, or whatever) and let it open for a "little" extension.

If its too big, think on a split? In order to avoid "minimonolits" and what would be the limit to consider an "app"/API a microservice or a little monolit?

Maybe to be more clear.

i.e:

Microservice/API
├── Product
│   └── DDD/CQRS/Hexagonal stuff
|       └── ....
├── Sells
│   └── DDD/CQRS/Hexagonal stuff
|       └── ....
└── Customer
   └── DDD/CQRS/Hexagonal stuff
       └── ....

Microservice with basic crud -> Product-Sells-Customer(with patterns such as CQRS, Hexagonal, etc...?) -> Its a minimonolit for me.

The kind of what I look forward...

Gateway microservice
├── Product
│   └── routing stuff
|       └── ....
├── Sells
│   └── routing stuff
|       └── ....
└── Customer
   └── routing stuff
       └── ....

Product

Product Microservice
├── Product
   └── Basic separation layer(REST/SERVICE/ORM-QUEUE)
       └── ....

Sells

Sells Microservice
├── Sells
   └── Basic separation layer(REST/SERVICE/ORM-QUEUE)
       └── ....

Customer

Customer Microservice
├── Customer
   └── Basic separation layer(REST/SERVICE/ORM-QUEUE)
       └── ....

The previous ones should have patterns such as CQRS, Hexagonal, etc...???

1
  • I agree that one should avoid mini-monoliths. Good thought, but I think spelling error. Commented Jul 21, 2022 at 14:24

1 Answer 1

5

The key thing to keep in mind is “microservices should be independently deployable and scalable”. If your framework and dependencies make your microservices need to be deployed en masse, you lose almost all of the benefit (and incur a lot more cost). That will drive a lot of your decisions about where to split things. Literal size doesn’t matter as much as coupling does.

In general, the depth of your layers matters less than the breath of the API surface area since layer coupling doesn’t usually prevent independent deployment. Where you run into problems is when different services access the same db - so need schema changes done together. Or when different services use the same authorization, so deploying one with an upgraded scheme causes auth failures. If each service’s presentation is coupled to its ORM... well, that’s unfortunate but you can still deploy your tiny service without breaking its neighbors.

6
  • 1
    This is the right answer. Mircoservices are a unit of deployment, not a unit of business logic.
    – John Wu
    Commented May 29, 2020 at 23:55
  • 1
    @JohnWu: aren't micro services kind of both? A unit of business logic that is independently deployable and scalable? It feels like ignoring the business logic aspect leads to making every distinct business operation it's own micro service. Commented May 30, 2020 at 13:41
  • 1
    Ok so lets say that we ignore the "design" of a microservice itself because its encapsulated and its "is own shit". So you are saying that to consider the scope of a microservice its more about features rather than business logic? And what about complexity of the system? With this approach you may end up with domains mixed in microservices because of its features? and when business requeriments change you may end up in good mess because the domain is splitted in several services? Commented May 30, 2020 at 15:25
  • 1
    Given how loosely defined “feature” and “domain” are, I’m not sure I can answer you well. But think of how you would design classes. Given a problem, you break it down into smaller chunks that are decoupled from one another. Decoupling means that inevitable future changes can be done more easily. It means that testing and reuse can be done more effectively. Microservices are a step larger than classes, but the same approach holds (in my experience).
    – Telastyn
    Commented May 30, 2020 at 15:30
  • 1
    Ok, thank you :) now I think I have a better vision of the microservices "ecosystem" and no matter of the size of the project as far as it can be easily scalable and doesn't impact "its neighbors/dependents" and for the project designs/services are not much a key for consider something a microservice. Good gone with the classes example, it helped me a lot :) Commented May 30, 2020 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.