Operations Runbook¶
Health & Monitoring¶
| Check | Endpoint | Use as |
|---|---|---|
| Liveness | GET /health/live (alias /health) |
Container/K8s liveness probe |
| Readiness | GET /health/ready → 503 if the DB is unreachable |
Readiness probe, load balancer health check |
| Metrics | GET /metrics |
Prometheus scrape target |
Every response carries X-Request-ID. Search logs for request_id to follow a single request, and for trace_id when OpenTelemetry is enabled.
Database Backups¶
Use your provider's point-in-time recovery for managed Postgres. For the Compose stack:
# Backup (custom format, compressed)
docker compose exec -T db pg_dump -U "$POSTGRES_USER" -d "$POSTGRES_DB" -Fc > backup-$(date +%F).dump
# Restore into an empty database
docker compose exec -T db pg_restore -U "$POSTGRES_USER" -d "$POSTGRES_DB" --clean --if-exists < backup-2026-01-01.dump
On the AWS free-tier deployment the database is Neon: use its point-in-time restore, or create a branch to inspect an earlier state.
Test restores regularly; an untested backup is not a backup.
Migrations¶
- Each deploy runs
scripts/prestart.sh, which runsalembic upgrade headand then the idempotent seed. - Roll back one revision:
alembic downgrade -1(from the image:docker compose run --rm prestart alembic downgrade -1). - Prefer expand/contract changes so the previous release keeps working during a rollout: add nullable columns first, backfill, then enforce constraints in a later release.
Audit Data Retention¶
user_activity (one row per request) and system_log (unhandled errors) grow continuously. Schedule the purge job, for example daily:
docker compose run --rm prestart python -m app.db.maintenance # AUDIT_RETENTION_DAYS (default 90)
docker compose run --rm prestart python -m app.db.maintenance --days 30
On AWS, EventBridge Scheduler runs it daily by invoking the worker function with {"job": "purge"} (purge_schedule in Terraform). To run it now: aws lambda invoke --function-name <name>-worker --payload '{"job":"purge"}' --cli-binary-format raw-in-base64-out out.json.
Security Operations¶
| Task | How | Effect |
|---|---|---|
| Sign a user out everywhere | User calls POST /login/logout, or an admin deactivates them |
token_version is incremented, so all of that user's tokens are rejected |
| Unlock a locked account | Wait ACCOUNT_LOCKOUT_MINUTES, or have the user reset their password |
Counter and lock cleared |
Rotate SECRET_KEY |
Deploy a new value | All tokens become invalid and everyone must sign in again |
| Rotate database password | Update the secret, then restart prestart and backend |
– |
| Investigate a 500 | SUPER: GET /api/v1/admin/dashboard/logs (paginated with page/size, search with q; stack trace, path and request_id) |
– |
| Verify alerting | SUPER: GET /api/v1/admin/dashboard/error-test |
Produces a deliberate 500 |
| Verify SMTP | SUPER: POST /api/v1/admin/dashboard/test-email?email_to=… |
Sends a test email |
Incident Checklist¶
- Check
/health/readyanddocker compose ps(or your orchestrator). - Find failing requests in the logs by
request_id, or in Sentry. - Look for recent deploys or migrations; roll back the image and, if needed,
alembic downgrade. - If credentials may have leaked: rotate
SECRET_KEYand the affected passwords, and reviewuser_activityfor the affected period. - Write a short post-incident note, and add an ADR if a decision changes.