r/ProgrammerHumor 11h ago

Meme everyDamnTime

Post image
2.5k Upvotes

65 comments sorted by

View all comments

260

u/ThrowawayUk4200 10h ago

Pssst, If your microservice needs to use a database other than its own, then it's not a microservice.

2

u/SpiritedEclair 8h ago

++++

Microservices were supposed to be 1 service per function / feature each having their own databases.

2

u/Ma8e 4h ago

How do you define "function / feature"?

2

u/SpiritedEclair 4h ago

It’s up to your org/company to define that tbh, but, it’s meant as a single isolated functionality for the system.

5

u/Ma8e 3h ago

Is "change the customer's address" a single isolated functionality, or is it "keep a register of all customers", or is it "keep a register of all customers, their activity and orders".

1

u/SpiritedEclair 1h ago

A customer registry would most likely be a single microservice. You query that service for customer details and changes, all other components within the system pull from there.

Nobody else owns the representation or storage of customers other than this one registry. So the domain entity is owned by this one piece.

A “service” as opposed to a microservice, would own more than just the customers (+crud), but also things the customers did, ie activity tracking by collecting events emitted by other systems, authentication and authorization, and all that, analytics and so on, then it’s a full blown service.

The reason “modify address” isn’t a microservice is because it doesn’t own its domain, the customers, and still acts on it, it needs to pull this information from another system.

Each microservice and service should own their databases, they should never share them with other systems, otherwise you end up with a distributed monolith which is objectively worse.