Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the Saga pattern in distributed transactions?
The Saga pattern breaks a large transaction into smaller, independent steps called sagas. Each step updates data and publishes an event. If a step fails, compensating actions undo previous steps to keep data consistent.
Click to reveal answer
beginner
How does the Saga pattern handle failures in a distributed system?
When a step in the saga fails, the pattern triggers compensating transactions that reverse the effects of previous successful steps, ensuring the system returns to a consistent state.
Click to reveal answer
intermediate
What are the two main coordination styles of the Saga pattern?
1. Choreography: Each service listens for events and decides when to act. 2. Orchestration: A central coordinator tells each service what to do next.
Click to reveal answer
intermediate
Why is the Saga pattern preferred over distributed two-phase commit in microservices?
Because it avoids locking resources for long times, improves scalability, and fits better with asynchronous communication common in microservices.
Click to reveal answer
beginner
What is a compensating transaction in the Saga pattern?
A compensating transaction is an action that reverses the effects of a previously completed step in the saga to maintain data consistency after a failure.
Click to reveal answer
What does a compensating transaction do in the Saga pattern?
AReverses a previous successful step
BCommits the current transaction
CStarts a new saga
DLocks resources for consistency
✗ Incorrect
Compensating transactions undo previous steps to keep data consistent after a failure.
Which coordination style uses a central controller in the Saga pattern?
AOrchestration
BTwo-phase commit
CEvent sourcing
DChoreography
✗ Incorrect
Orchestration uses a central coordinator to manage saga steps.
Why is the Saga pattern better than two-phase commit for microservices?
AIt locks resources longer
BIt is synchronous
CIt improves scalability and uses asynchronous communication
DIt requires a central database
✗ Incorrect
Saga pattern avoids long locks and fits asynchronous microservices better.
In the Saga pattern, what triggers the next step in choreography style?
AA central coordinator
BAn event published by the previous step
CA timeout event
DManual intervention
✗ Incorrect
Each service listens for events from previous steps to continue the saga.
What is the main goal of the Saga pattern?
ATo centralize all business logic
BTo lock all resources during a transaction
CTo speed up database queries
DTo maintain data consistency across services without distributed locks
✗ Incorrect
Saga ensures data consistency in distributed systems without locking resources.
Explain how the Saga pattern manages distributed transactions and handles failures.
Think about how each step is independent and how the system recovers if something goes wrong.
You got /4 concepts.
Compare choreography and orchestration styles in the Saga pattern.
Consider who controls the flow of the saga in each style.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of the Saga pattern in microservices?
easy
A. To replicate data across multiple databases synchronously
B. To manage distributed transactions by breaking them into smaller steps with compensations
C. To speed up database queries by caching results
D. To lock all resources until the transaction completes
Thinking Saga locks resources like traditional transactions
5. You design a payment system using Saga pattern with steps: debit account, reserve inventory, and confirm order. If inventory reservation fails, what should happen?
hard
A. Run compensation to credit back the debited amount and abort order confirmation
B. Ignore failure and proceed to confirm order
C. Retry inventory reservation indefinitely without compensation
D. Lock all services until inventory is reserved
Solution
Step 1: Understand Saga compensation in payment flow
If inventory reservation fails, previous successful steps (debit account) must be undone to avoid inconsistent state.
Step 2: Apply compensation and abort
Compensation credits back the debited amount, and order confirmation is aborted to maintain consistency.
Final Answer:
Run compensation to credit back the debited amount and abort order confirmation -> Option A
Quick Check:
Failure triggers compensation rollback and abort [OK]
Hint: Failure in middle step triggers rollback of prior steps [OK]
Common Mistakes:
Proceeding despite failure causing inconsistent state