Course contentsShow
← Software Engineering
Lesson 1422 of 1,93341. Scalability and Distributed SystemsFree lesson

When to Avoid Distributed Transactions

Recognizing when to use eventual consistency, event sourcing, or domain redesign instead of distributed transactions.

When to Avoid Distributed Transactions

You'll learn: How to recognize when simpler alternatives like eventual consistency, event sourcing, or domain redesign are better choices than distributed transactions.

The Core Problem

Distributed transactions (like two-phase commit) guarantee strong consistency across multiple services or databases, but at a steep cost: they lock resources, reduce availability, increase latency, and create tight coupling. Often, you're paying too much for guarantees you don't actually need.

When to Choose Alternatives

Eventual Consistency Is Enough

Many business requirements don't actually need immediate consistency. If "eventually correct" is acceptable (inventory counts, analytics, user profiles), use asynchronous messaging or the saga pattern with choreography instead. Your system stays available even when parts fail.

Event Sourcing Fits Better

When you need a reliable audit trail or the ability to rebuild state, event sourcing naturally provides consistency through an immutable event log—without distributed locks. Commands can fail independently, and projections catch up asynchronously.

Domain Boundaries Are Wrong

If you constantly need distributed transactions between services, your boundaries may be incorrect. Consider redesigning: merge related data into one service, or accept that different bounded contexts don't need transactional consistency between them. A banking account transfer within one bank? One transaction. Between banks? Eventual consistency with reconciliation.

Performance and Availability Matter More

Distributed transactions block and wait. If you need high throughput or can't afford downtime during network partitions (remember CAP theorem?), prefer AP-style systems with compensation logic over CP-style distributed transactions.

Key Takeaway: Avoid distributed transactions when eventual consistency meets your business needs, when event sourcing provides better semantics, when your domain boundaries need rethinking, or when availability and performance outweigh immediate consistency guarantees.