# Rollback & incident runbook

Use this runbook during production incidents or failed deployments. Keep commands exact, test restore procedures before launch, and never paste secrets here.

## First 5 minutes (Triage)

- [ ] Confirm the symptom (HTTP 5xx, broken auth/form, asset mismatch, slow queries, or third-party outage).
- [ ] Identify scope: all users, specific route, or single integration.
- [ ] Halt any in-progress deployment or automated migration.
- [ ] Capture recent logs, current commit/image tag, and error timestamps before restarting services.

## Recovery decision table

| Situation | Safe recovery path | Watch out for |
| --- | --- | --- |
| Bad app code or template change (no schema migration) | Roll back to previous release tag/image and verify static assets | Cached CDN/browser manifests if asset hashes changed |
| Misconfigured environment variable or feature flag | Fix env config in host/vault and restart service | Verify secret rotation didn't invalidate active sessions |
| Additive DB migration (`CREATE TABLE` / nullable column) + bad app code | Roll back app release; leave additive schema intact or reverse cleanly | Do not blindly run destructive reverse migrations in production |
| Destructive DB migration or corrupted data write | Put app in maintenance mode, restore pre-deploy snapshot, then deploy previous release | Data created between backup timestamp and restore will be lost—record window |
| Third-party API/SMTP outage | Verify graceful degradation/error handling and queue or log failed jobs | Avoid tight retry loops that exhaust rate limits |

## Code rollback procedure

1. Identify the last known-good release/commit/image: `<command or tag lookup>`
2. Check out or redeploy the previous release: `<exact deploy/rollback command>`
3. Rebuild or verify collected static assets / cache manifest: `<command>`
4. Restart the application service and confirm healthy status: `<health command>`
5. Re-run critical smoke tests (home, auth/admin, primary form, static CSS/JS HTTP 200).

## Database restore procedure

1. Confirm pre-incident backup file and checksum from `<backup location>`.
2. Stop write traffic / background workers before replacing the database.
3. Restore into a verification copy first if time permits; otherwise execute restore command: `<exact restore command>`
4. Run integrity check and verify schema migration state (`migrate --check` / table row sanity check).
5. Resume traffic and verify key user journeys end-to-end.

## Post-incident review

- **Incident date & duration:**
- **User / business impact:**
- **Triggering change or root cause:**
- **What slowed down detection or recovery?**
- **Preventive fixes (test, alert, guard, or runbook update) with owner & due date:**
