0
0
Microservicessystem_design~20 mins

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

Choose your learning style9 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 microservices?

Consider a system where multiple microservices need to update their data as part of a single business transaction. What is the main goal of using the Saga pattern in this context?

ATo coordinate a sequence of local transactions with compensating actions to maintain data consistency without distributed locks.
BTo ensure all microservices update their data atomically using distributed locks.
CTo replicate data synchronously across all microservices to avoid inconsistencies.
DTo use a centralized database to handle all transactions for microservices.
Attempts:
2 left
💡 Hint

Think about how Saga handles failures without locking resources across services.

Architecture
intermediate
2:00remaining
Which architecture best represents the Saga pattern with event-based choreography?

In the Saga pattern, event-based choreography means services react to events to continue the transaction. Which diagram best shows this flow?

AAll services update a shared database table to track transaction progress.
BA central orchestrator sends commands to each service to perform transactions in order.
CEach service publishes events after completing its local transaction, triggering the next service to act without a central coordinator.
DServices use distributed locks to coordinate transaction steps.
Attempts:
2 left
💡 Hint

Think about how services communicate without a central controller in event-based choreography.

scaling
advanced
2:00remaining
How does the Saga pattern help scale distributed transactions in microservices?

Imagine a high-traffic system with many distributed transactions. How does using the Saga pattern improve scalability compared to traditional two-phase commit?

ABy locking all resources globally during the transaction to prevent conflicts.
BBy requiring all services to complete their transactions before any service commits.
CBy using a single database instance to handle all transaction coordination.
DBy breaking transactions into smaller local steps that can run independently and asynchronously, reducing blocking and contention.
Attempts:
2 left
💡 Hint

Consider how asynchronous local transactions affect system throughput and resource usage.

tradeoff
advanced
2:00remaining
What is a key tradeoff when using the Saga pattern for distributed transactions?

While the Saga pattern improves scalability and availability, what is a common tradeoff developers must handle?

AIt guarantees strong consistency across all services at all times.
BIt requires complex compensating transactions and eventual consistency, which can complicate error handling.
CIt eliminates the need for any transaction coordination or monitoring.
DIt forces all services to use the same database technology.
Attempts:
2 left
💡 Hint

Think about what happens if a step in the Saga fails after some steps have succeeded.

estimation
expert
3:00remaining
Estimate the maximum throughput impact of Saga pattern compensations in a system with 1000 transactions per second and 5% failure rate at step 3.

A Saga consists of 5 steps. Step 3 fails in 5% of transactions, triggering compensations for steps 1 and 2. Each compensation takes 10ms. What is the approximate additional processing time per second due to compensations?

A1000 transactions * 5% failures * 2 compensations * 10ms = 1000ms (1 second) extra processing per second.
B1000 transactions * 5% failures * 5 steps * 10ms = 2500ms (2.5 seconds) extra processing per second.
C1000 transactions * 10ms = 10,000ms (10 seconds) extra processing per second.
D1000 transactions * 5% failures * 10ms = 500ms (0.5 seconds) extra processing per second.
Attempts:
2 left
💡 Hint

Calculate how many compensations run per second and multiply by their duration.