Transactions, Migrations, and Backups
Use transactions for invariants spanning records; use atomic updates and unique constraints to prevent common races.
How to apply it
Use expand-and-contract migrations: add compatible fields, deploy dual-read code, backfill, switch writes, verify, then remove legacy fields later. Encrypt backups and test restoration in isolation. Define RPO/RTO and retention across databases, object storage, logs, and exports.
Worked example
For a field rename, support old and new fields during rollout, backfill, measure remaining legacy records, then remove the old field.
Common mistakes to avoid
Assuming successful backup jobs prove recoverability or removing fields before old app versions are gone.
Practice task
Implement this concept in the capstone. Add one positive test, one negative or failure-path test, and a short note explaining the trade-off you chose.
- Use transactions for invariants spanning records; use atomic updates and unique constraints to prevent common races.
- Use expand-and-contract migrations: add compatible fields, deploy dual-read code, backfill, switch writes, verify, then remove legacy fields later.
What is the strongest production practice for Transactions, Migrations, and Backups?