Bird
Raised Fist0
Kafkadevops~20 mins

Saga pattern for distributed transactions in Kafka - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Saga Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the primary purpose of the Saga pattern in distributed systems?
Choose the best explanation for why the Saga pattern is used in distributed transactions.
ATo replicate data synchronously across all services to avoid inconsistencies.
BTo lock all resources across microservices until the entire transaction completes to ensure atomicity.
CTo coordinate a sequence of local transactions with compensating actions to maintain data consistency without locking resources.
DTo batch all operations into a single monolithic transaction for performance.
Attempts:
2 left
💡 Hint
Think about how distributed systems avoid long locks and still keep data consistent.
❓ Architecture
intermediate
2:00remaining
Which Kafka component is best suited to implement the Saga pattern's event coordination?
Select the Kafka component that helps orchestrate and communicate the sequence of events in a Saga.
AKafka Connect to synchronize databases directly without event handling.
BKafka Schema Registry to store transaction logs.
CKafka Streams to batch process unrelated data without event ordering.
DKafka Topics to publish and subscribe to events representing transaction steps and compensations.
Attempts:
2 left
💡 Hint
Think about how services communicate asynchronously in a Saga.
❓ scaling
advanced
2:30remaining
How does the Saga pattern scale when handling thousands of distributed transactions concurrently?
Choose the best explanation of how Saga pattern scales in a Kafka-based microservices environment.
ABy replicating the entire Saga state machine on every microservice instance to avoid coordination.
BBy partitioning Kafka topics and processing events in parallel, allowing independent Sagas to run concurrently without interference.
CBy batching all transactions into one large event to reduce overhead.
DBy serializing all transactions through a single Kafka partition to maintain strict order.
Attempts:
2 left
💡 Hint
Consider how Kafka partitions help parallelize event processing.
❓ tradeoff
advanced
2:30remaining
What is a key tradeoff when using the Saga pattern compared to traditional two-phase commit (2PC)?
Select the option that best describes a tradeoff of Saga pattern usage.
ASaga provides eventual consistency but sacrifices immediate atomicity and may require compensating transactions.
BSaga guarantees immediate atomicity but requires locking all resources during the transaction.
CSaga eliminates the need for compensating transactions by using distributed locks.
DSaga reduces network overhead by batching all operations synchronously.
Attempts:
2 left
💡 Hint
Think about consistency guarantees and how compensations work.
❓ estimation
expert
3:00remaining
Estimate the maximum throughput of a Saga-based system using Kafka with 10 partitions, each processing 1000 events per second, assuming each Saga requires 5 events.
Calculate the maximum number of Saga transactions the system can handle per second.
A2000 Saga transactions per second
B5000 Saga transactions per second
C500 Saga transactions per second
D10000 Saga transactions per second
Attempts:
2 left
💡 Hint
Divide total event processing capacity by events per Saga.

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

  1. Step 1: Understand the Saga pattern concept

    The Saga pattern divides a big transaction into smaller, manageable steps that can be undone if needed.
  2. Step 2: Identify the main goal

    Its goal is to maintain data consistency across services without locking resources for a long time.
  3. Final Answer:

    To break a large transaction into smaller steps with compensations -> Option C
  4. 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

  1. Step 1: Identify Kafka components used in Saga

    Saga relies on events to coordinate steps, so Kafka topics are used to send these events.
  2. Step 2: Exclude unrelated Kafka features

    Encryption, backups, and load balancing are not the main focus for Saga coordination.
  3. Final Answer:

    Kafka topics for event communication -> Option D
  4. 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

  1. Step 1: Understand failure handling in Saga

    If a step fails, previous successful steps must be undone using compensating actions.
  2. Step 2: Apply to the scenario

    Since step B failed after A succeeded, step A must be compensated by sending a rollback event.
  3. Final Answer:

    Step A is compensated by sending a rollback event -> Option A
  4. 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

  1. Step 1: Identify compensation trigger mechanism

    Compensation happens when a service listens for failure events and reacts by sending rollback events.
  2. Step 2: Analyze the problem

    If compensations are missing, likely the service is not listening or handling failure events properly.
  3. Final Answer:

    The service does not listen to failure events to trigger compensation -> Option A
  4. 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
  • Assuming broker overload causes missing compensations
5. You design a Saga with multiple microservices communicating via Kafka. To ensure scalability and fault tolerance, which approach is best?
hard
A. Store Saga state only in a centralized database without event logs
B. Use separate Kafka topics per Saga step and implement idempotent consumers
C. Use a single Kafka topic for all Saga events without consumer groups
D. Send synchronous HTTP calls between services instead of Kafka events

Solution

  1. Step 1: Consider scalability and fault tolerance needs

    Separate topics per step allow independent scaling and isolation of events.
  2. Step 2: Ensure idempotency in consumers

    Idempotent consumers prevent duplicate processing on retries, improving fault tolerance.
  3. Step 3: Evaluate other options

    Single topic without consumer groups limits scalability; centralized DB without events loses Saga benefits; synchronous calls reduce fault tolerance.
  4. Final Answer:

    Use separate Kafka topics per Saga step and implement idempotent consumers -> Option B
  5. Quick Check:

    Separate topics + idempotent consumers = scalable Saga [OK]
Hint: Separate topics and idempotent consumers scale Saga well [OK]
Common Mistakes:
  • Using one topic for all events limits scaling
  • Ignoring idempotency causes duplicate side effects
  • Relying on synchronous calls reduces fault tolerance
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard