Transaction States and Lifecycle

Transaction States

Think of transaction states like a job application process:

  1. Active: Transaction is running (like "application submitted")

  2. Partially Committed: All operations done, but not yet saved permanently (like "under review")

  3. Committed: Successfully completed and saved (like "job offer accepted")

  4. Failed: Something went wrong (like "application rejected")

  5. Aborted: All changes undone, back to original state (like "withdrew application")

State Transitions:-

Handling External Actions

Problem: Some actions can't be undone (like sending email, dispensing cash) Solution: Perform external actions only AFTER commit

ATM Example:

  1. Check balance, deduct amount

  2. Commit transaction

  3. Only then dispense cash

  4. If crash happens after commit but before dispensing, compensating transaction adds money back

Updated on