Bird
Raised Fist0
HLDsystem_design~10 mins

Saga pattern for distributed transactions in HLD - 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 the first step in a saga transaction.

HLD
def saga_step_1():
    # Start transaction
    [1]
Drag options to blanks, or click blank then click option'
Abegin_transaction()
Bcommit_transaction()
Crollback_transaction()
Dend_transaction()
Attempts:
3 left
💡 Hint
Common Mistakes
Using commit_transaction() before starting the transaction.
Calling rollback_transaction() as the first step.
2fill in blank
medium

Complete the code to define the compensation action in a saga step.

HLD
def compensate_step():
    # Undo previous action
    [1]
Drag options to blanks, or click blank then click option'
Acommit_transaction()
Bexecute_compensation()
Crollback_compensation()
Dstart_compensation()
Attempts:
3 left
💡 Hint
Common Mistakes
Using commit_transaction() instead of compensation.
Calling rollback_compensation() which is not a standard term.
3fill in blank
hard

Fix the error in the saga coordinator logic to handle step failure.

HLD
def saga_coordinator():
    try:
        execute_step_1()
        execute_step_2()
    except Exception:
        [1]  # Handle failure
Drag options to blanks, or click blank then click option'
Aexecute_compensation()
Bcommit_transaction()
Cstart_transaction()
Dignore_error()
Attempts:
3 left
💡 Hint
Common Mistakes
Committing the transaction on failure.
Ignoring the error without compensation.
4fill in blank
hard

Fill both blanks to correctly define a saga step with its compensation.

HLD
def saga_step():
    try:
        [1]  # Perform action
    except Exception:
        [2]  # Perform compensation
Drag options to blanks, or click blank then click option'
Aexecute_action()
Bexecute_compensation()
Ccommit_transaction()
Dstart_transaction()
Attempts:
3 left
💡 Hint
Common Mistakes
Using commit_transaction() instead of compensation.
Starting a transaction inside the step incorrectly.
5fill in blank
hard

Fill all three blanks to define a saga coordinator managing steps and compensation.

HLD
def saga_coordinator():
    [1]  # Start saga
    try:
        [2]  # Execute saga steps
    except Exception:
        [3]  # Execute compensation
Drag options to blanks, or click blank then click option'
Astart_transaction()
Bexecute_all_steps()
Cexecute_compensation()
Dcommit_transaction()
Attempts:
3 left
💡 Hint
Common Mistakes
Committing before executing all steps.
Not starting the transaction before steps.