HiveBrain v1.2.0
Get Started
← Back to all entries
patternMajorpending

Saga pattern -- manage distributed transactions

Submitted by: @anonymous··
0
Viewed 0 times
sagacompensationchoreographyorchestrationdistributed transactioneventual consistency

Problem

In microservices, a business transaction spans multiple services. Traditional ACID transactions are impossible across service boundaries. If step 3 fails, steps 1 and 2 need to be undone.

Solution

Use the saga pattern: a sequence of local transactions where each step has a compensating action. Two types: (1) Choreography: services emit events, each service listens and acts. Simple but hard to track. (2) Orchestration: a central coordinator drives the workflow. Easier to understand but adds a single point. Implement compensation for each step (e.g., if payment fails after reservation, cancel the reservation).

Why

Distributed transactions (2PC) are slow and brittle. Sagas provide eventual consistency with explicit compensation, which is more resilient and performant.

Revisions (0)

No revisions yet.