beginnerData Consistency & Duplication Challenges

Why do modern microservices architectures generally avoid Two-Phase Commit for cross-service consistency?

Two-Phase Commit requires a coordinator to get every participating database to 'prepare' its part of a change and hold locks on the affected data until a final commit or rollback decision arrives. This forces every participant to stay synchronously available for the full duration of the process, and if the coordinator itself crashes partway through, participants can be left holding locks indefinitely with no decision ever arriving. That directly conflicts with the reasons services were split into independent databases in the first place — independent availability and independent scaling — since a service can no longer be truly independent if it might be blocked waiting on a coordinator elsewhere. Most microservices architectures instead use a sequence of local, independent transactions with an explicit compensation plan for undoing earlier steps if a later one fails, commonly known as the saga pattern.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to What problem can occur when you separate the write and read databases without using event sourcing?← Back to all Event-Driven Microservices questions