Level 6 / Project 05 - Transaction Rollback Drill¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| — | This project | — | — | Flashcards | — | — |
Focus¶
- rollback-first failure handling
Why this project exists¶
This project gives you level-appropriate practice in a realistic operations context. Goal: run the baseline, alter behavior, break one assumption, recover safely, and explain the fix.
Run (copy/paste)¶
Use <repo-root> as the folder containing this repository's README.md.
cd <repo-root>/projects/level-6/05-transaction-rollback-drill
python project.py --input data/sample_input.txt --output data/output_summary.json
pytest -q
Expected terminal output¶
{
"committed": 3,
"rolled_back": 1,
"final_accounts": [
{"id": 1, "name": "Alice", "balance": 425.0},
...
]
}
Expected artifacts¶
data/output_summary.json— transfer results with account balances- Passing tests (
pytest -q→ 6+ passed) - Updated
notes.md
Alter it (required)¶
- Add a transfer fee: deduct an extra 1% from the source account on each successful transfer.
- Add a
--max-amountflag that rejects any single transfer above a threshold. - Add a
rollback_allmode: if any transfer in the batch fails, roll back the entire batch. - Re-run script and tests after each change.
Break it (required)¶
- Transfer the exact full balance (e.g. 500.00 from an account with 500.00) — does the CHECK constraint allow balance = 0?
- Transfer between the same account (from=1, to=1) — what happens?
- Remove the SAVEPOINT logic and observe what happens when a mid-batch transfer fails.
Fix it (required)¶
- Add a guard that rejects self-transfers (from_id == to_id).
- Ensure the CHECK constraint allows zero balance but not negative.
- Add a test that proves savepoints isolate failures from successful transfers.
Explain it (teach-back)¶
- What is a SAVEPOINT, and how does it differ from a regular transaction?
- Why can we roll back a single transfer without losing the others?
- What would happen without explicit transaction control (autocommit mode)?
- How do real banks handle the "insufficient funds" scenario at scale?
Mastery check¶
You can move on when you can: - run baseline without docs, - explain one core function line-by-line, - break and recover in one session, - keep tests passing after your change.
Related Concepts¶
| ← Prev | Home | Next → |
|---|---|---|