🔁 Data & Database Design · Data & Databases
Transactions
Group related database changes so they succeed or fail together.
Partial updates can create invalid data.
Creating an order and its required items rolls back if a critical save fails.
💡 Like a bank transfer: the money must leave one account and arrive in the other as one move — never vanish halfway.
💡 Why it matters
Many business actions touch several rows that must all change or none at all. A transaction wraps them so a crash or error cannot leave half-finished, invalid data behind. This all-or-nothing guarantee is what keeps the database trustworthy under failures and concurrent use.
🛠️ How to achieve it
⚠️ Signs of trouble
- •A failed operation leaves half the data saved.
- •Totals or balances sometimes do not add up.
- •Long-running transactions block other users.
- •Related rows exist without their partners.
🎯 Quick check
Score: 0/3Three questions to test the idea.
1. What does a transaction guarantee?
Answer: Grouped changes all succeed or all fail together
A transaction is all-or-nothing: either every change commits, or they all roll back, so no partial data survives.
2. An order saves but its required items fail. With a transaction, what happens?
Answer: The whole thing rolls back, leaving no partial order
Because the writes are in one transaction, a failed step rolls everything back — no half-saved order remains.
3. Why keep transactions short?
Answer: Long ones block other users and risk timeouts
A transaction holds locks until it finishes, so a long one makes others wait and can time out.
