What is the Saga pattern in distributed transactions?
The Saga pattern breaks a large transaction into smaller steps, each with a compensating action to undo it if needed. It helps keep data consistent across services without locking resources.
Click to reveal answer
intermediate
How does Kafka help implement the Saga pattern?
Kafka acts as a message broker to send events between services. Each service listens for events, performs its step, and publishes the next event or a compensation event if something fails.
Click to reveal answer
beginner
What is a compensating transaction in the Saga pattern?
A compensating transaction is an action that reverses a previous step if the saga fails later. It helps undo partial changes to keep the system consistent.
Click to reveal answer
intermediate
What are the two main types of Saga implementations?
1. Choreography: Services communicate by producing and consuming events without a central coordinator. 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?
Saga avoids locking resources and long waits by using asynchronous steps and compensations. It scales better and fits microservices' independent nature.
Click to reveal answer
What role does Kafka play in the Saga pattern?
AMessage broker to pass events between services
BDatabase to store all transactions
CLoad balancer for microservices
DAuthentication service
✗ Incorrect
Kafka is used as a message broker to send and receive events that coordinate saga steps.
What is a compensating transaction?
AA step that confirms the transaction
BAn action that reverses a previous step if needed
CA database commit operation
DA service that starts the saga
✗ Incorrect
Compensating transactions undo previous steps to maintain consistency if the saga fails.
Which Saga implementation uses a central coordinator?
ATwo-phase commit
BChoreography
COrchestration
DEvent sourcing
✗ Incorrect
Orchestration uses a central coordinator to direct saga steps.
Why is Saga pattern better than two-phase commit in microservices?
AIt avoids resource locking and scales better
BIt locks resources longer
CIt uses synchronous calls only
DIt requires a single database
✗ Incorrect
Saga uses asynchronous steps and compensations, avoiding locks and fitting microservices.
In Saga, what triggers the next step in the transaction?
AA database trigger
BA manual user action
CA timer
DAn event published to Kafka
✗ Incorrect
Each service publishes an event to Kafka to trigger the next step.
Explain how the Saga pattern manages distributed transactions using Kafka.
Think about how services talk and undo work if needed.
You got /4 concepts.
Describe the advantages of using the Saga pattern over traditional two-phase commit in microservices.
Focus on why Saga suits distributed systems better.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of the Saga pattern in distributed systems?
easy
A. To encrypt messages between microservices
B. To speed up database queries by caching results
C. To break a large transaction into smaller steps with compensations
D. To create backups of all data in real-time
Solution
Step 1: Understand the Saga pattern concept
The Saga pattern divides a big transaction into smaller, manageable steps that can be undone if needed.
Step 2: Identify the main goal
Its goal is to maintain data consistency across services without locking resources for a long time.
Final Answer:
To break a large transaction into smaller steps with compensations -> Option C
Quick Check:
Saga pattern = smaller steps with undo [OK]
Hint: Saga splits big tasks into small reversible steps [OK]
Common Mistakes:
Confusing Saga with caching or encryption
Thinking Saga creates backups
Assuming Saga speeds up queries
2. Which Kafka feature is most important for implementing the Saga pattern?
easy
A. Kafka Streams for data encryption
B. Kafka Consumer groups for load balancing
C. Kafka Connect for database backups
D. Kafka topics for event communication
Solution
Step 1: Identify Kafka components used in Saga
Saga relies on events to coordinate steps, so Kafka topics are used to send these events.
Step 2: Exclude unrelated Kafka features
Encryption, backups, and load balancing are not the main focus for Saga coordination.
Final Answer:
Kafka topics for event communication -> Option D
Quick Check:
Kafka topics = event communication [OK]
Hint: Saga uses Kafka topics to send events between services [OK]
Common Mistakes:
Confusing Kafka Streams with event messaging
Thinking Kafka Connect handles Saga coordination
Mixing consumer groups with transaction steps
3. Given a Saga with three steps: A, B, and C, where each step publishes an event to Kafka, what happens if step B fails after step A succeeds?
medium
A. Step A is compensated by sending a rollback event
B. Step C executes anyway to complete the transaction
C. The entire Saga is aborted without compensation
D. Step B retries indefinitely without affecting others
Solution
Step 1: Understand failure handling in Saga
If a step fails, previous successful steps must be undone using compensating actions.
Step 2: Apply to the scenario
Since step B failed after A succeeded, step A must be compensated by sending a rollback event.
Final Answer:
Step A is compensated by sending a rollback event -> Option A
Quick Check:
Failure in step B triggers compensation for step A [OK]
Hint: Failed step triggers compensation for prior steps [OK]
Common Mistakes:
Assuming next steps run despite failure
Thinking Saga aborts without compensation
Believing retries never stop
4. A developer implemented a Saga using Kafka but notices that compensating events are not triggered on failure. What is the most likely cause?
medium
A. The service does not listen to failure events to trigger compensation
B. Kafka topics are not partitioned correctly
C. Kafka consumer group ID is missing
D. Kafka brokers are overloaded
Solution
Step 1: Identify compensation trigger mechanism
Compensation happens when a service listens for failure events and reacts by sending rollback events.
Step 2: Analyze the problem
If compensations are missing, likely the service is not listening or handling failure events properly.
Final Answer:
The service does not listen to failure events to trigger compensation -> Option A
Quick Check:
Missing compensation = no failure event listener [OK]
Hint: Compensation needs failure event listeners active [OK]
Common Mistakes:
Blaming Kafka partitions for compensation logic
Confusing consumer group ID with compensation triggers