0
0
Microservicessystem_design~10 mins

Saga pattern for distributed transactions in Microservices - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a saga step that triggers a local transaction.

Microservices
def saga_step():
    # Start local transaction
    [1]()
    # Proceed to next step
Drag options to blanks, or click blank then click option'
Abegin_transaction
Bcommit_transaction
Crollback_transaction
Dsend_compensate
Attempts:
3 left
💡 Hint
Common Mistakes
Using commit_transaction instead of begin_transaction.
2fill in blank
medium

Complete the code to send a compensation event when a saga step fails.

Microservices
def handle_failure():
    # Send compensation event
    [1]('compensate')
Drag options to blanks, or click blank then click option'
Astart_transaction
Brollback_transaction
Ccommit_transaction
Dsend_event
Attempts:
3 left
💡 Hint
Common Mistakes
Using commit_transaction instead of sending an event.
3fill in blank
hard

Fix the error in the saga coordinator code to correctly handle step completion.

Microservices
def saga_coordinator(event):
    if event.type == 'step_completed':
        [1]()  # Proceed to next saga step
Drag options to blanks, or click blank then click option'
Astart_saga
Btrigger_next_step
Csend_compensation
Drollback_saga
Attempts:
3 left
💡 Hint
Common Mistakes
Calling send_compensation instead of triggering next step.
4fill in blank
hard

Fill both blanks to define a saga step that executes a local transaction and sends a success event.

Microservices
def execute_step():
    [1]()  # Commit transaction
    [2]('step_completed')  # Notify coordinator
Drag options to blanks, or click blank then click option'
Acommit_transaction
Bsend_event
Cbegin_transaction
Drollback_transaction
Attempts:
3 left
💡 Hint
Common Mistakes
Reversing the order or using rollback instead of commit.
5fill in blank
hard

Fill all three blanks to implement a saga step that begins a transaction, handles failure by sending compensation, and commits on success.

Microservices
def saga_step_handler():
    [1]()  # Begin transaction
    try:
        process_local_transaction()
        [2]()  # Commit transaction
    except Exception:
        [3]('compensate')  # Send compensation event
Drag options to blanks, or click blank then click option'
Abegin_transaction
Bcommit_transaction
Csend_event
Drollback_transaction
Attempts:
3 left
💡 Hint
Common Mistakes
Using rollback_transaction instead of sending compensation event.