5 ms·
The problem with microservices is that your state is spread over multiple systems. You completely lose the concept of transactional integrity, so you will have
by amelius 10y ago
The problem with microservices is that your state is spread over multiple systems. You completely lose the concept of transactional integrity, so you will have to work around that from the start.
The advantage though is that APIs (system boundaries) are usually better defined.
Perhaps one should use the best of both worlds, and run microservices on a common database, and somehow allow to pass transactions between services (so multiple services can act within the same transaction).
- alexhornbake 10y agoOne of the big advantages of microservices is scaling/migrating the databases behind each service independently. If you need transactions across multiple services then one could argue that either your API endpoint is doing too much, or your services are doing too little. It's not perfect, and certainly not always convenient, but it's a balance. Microservices with a common DB is asking for trouble. The monolith is a better option in that case IMO.
- nbevans 10y agoIdempotency, event sourcing and sagas with compensations are ways to solve your problem. A shared database is an anti-pattern in distributed systems. Similarly, distributed transactions (ala. DTC) is an anti-pattern. Distributed systems aren't hard. They're just different.
- prodigal_erik 10y agoSay you sell a widget. You want to update both your cash account and your inventory, and never one without the other. Which is easier to understand and more reliable: doing them atomically, or making sure you have designed in 2^n intermediate states and all the code required to complete work that should happen but hasn't yet?
- kafkaesq 10y agoThe problem with microservices is that your state is spread over multiple systems. Then again, sometimes it's advantageous to identify parts of your system where aspects of state can be safely decoupled. And in which having them reside in disparate systems (and yes, sometimes be inconsistent or differently available) might actually be a better overall fit. You completely lose the concept of transactional integrity, so you will have to work around that from the start. Then again, sometimes your state changes not only don't need to be transactional; it can be disadvantageous to think of them that way. Depends, depends, depends.
- amelius 10y ago> Then again, sometimes your state changes not only don't need to be transactional; it can be disadvantageous to think of them that way. I'm curious; in what kinds of situation would this apply? > Depends, depends, depends. Flexibility is usually an important requirement. Often you cannot freeze your architecture and be done with it. I think a transactional approach could better fit with this.
- kafkaesq 10y agoI'm curious; in what kinds of situation would this apply? Any situation where the business value of having your state be 100% consistent does not outweigh the performance or implementation cost of making it so.