Build docs
Open the formatted HTML version
PhoneBazaar: Ops Runbook
Stage 6 of the AiNa pipeline (ops) · 2026-11-30 · inputs: Dev notes
Ops summary
- Stack being deployed: FastAPI 0.115 + Jinja2 + HTMX, Python 3.12, one app (
index.py→app.main:app). - Hosting model: Vercel serverless Python functions. Project
phonebazaar(teamshafi-3037), custom domainphonebazaar.tehchand.com, production deploys from the CLI. - DB engine + backup strategy: SQLite in
/tmp, seeded fromapp/app/catalog.pyon cold start. It is ephemeral by design for the demo, so there is nothing to back up: the catalog lives in git and orders are demo data. Phase 2 moves to managed Postgres with daily provider backups and 7-day point-in-time recovery. - Monitoring tooling recommended: Vercel runtime logs and deployment status now; free uptime check on
/healthz(Better Stack or UptimeRobot, 1-minute interval); Sentry in Phase 2. - SLO targets (demo): 99.5% monthly availability on
/healthz; p95 page TTFB under 800 ms (warm); checkout error rate under 1%. - Number of runbooks: 6 (below).
- Outstanding gaps: data resets on cold start; single shared admin password with no rate limiting; no CSRF tokens; Vercel git integration not yet connected because the Vercel account needs a GitHub login connection (see R6).
1. Deployment
Environments
| Env | URL | How it deploys |
|---|---|---|
| Production | https://phonebazaar.tehchand.com (alias of phonebazaar.vercel.app) |
vercel --prod from the repo root (wrapped by tools/publish.sh) |
| Local | http://localhost:8000 | cd app && python -m uvicorn app.main:app --reload |
| Container (optional) | any VPS | docker build -t phonebazaar app && docker run -p 8000:8000 -e ADMIN_PASSWORD=… -e SESSION_SECRET=… phonebazaar (starter Dockerfile) |
Configuration
| Variable | Set in | Notes |
|---|---|---|
ADMIN_PASSWORD |
Vercel → Production | The operator's copy is PHONEBAZAAR_ADMIN_PASSWORD in the private keys file. Never commit it. |
SESSION_SECRET |
Vercel → Production | 64 hex chars. Rotating it logs everyone out and empties carts (harmless). |
VERCEL |
set by Vercel | Switches the DB to /tmp and turns on Secure cookies |
List what's set (names only): vercel env ls production.
Standard release
cd app && python -m pytest -q # must be green
cd .. && bash tools/publish.sh "<what changed>" <doc-slug>
publish.sh regenerates docs/html, commits, pushes to github.com/shafialtn/phonebazaar, deploys to production, and curls /healthz plus the doc page. Treat any non-200 as a failed release and follow R2.
2. Monitoring
| Signal | Source | Threshold | Action |
|---|---|---|---|
/healthz returns ok |
Uptime monitor, every 1 min | 2 consecutive failures | Page the owner (email/phone) → R1 |
| 5xx rate | vercel logs phonebazaar.tehchand.com |
> 1% over 15 min | R3 |
| Function duration | Vercel dashboard → Observability | p95 > 2 s | R4 |
| Deploy state | vercel ls phonebazaar |
Not Ready |
R2 |
| TLS / domain | vercel domains inspect phonebazaar.tehchand.com |
Cert expiry < 14 days | Vercel auto-renews; check DNS |
/healthz opens the DB and counts phones, so it catches both a crashed function and a failed seed (the response is then empty).
3. Runbooks
R1. Site down (healthz failing)
curl -i https://phonebazaar.tehchand.com/healthz. Look at the status code and body.vercel ls phonebazaar. Is the latest production deploymentReady?vercel logs <deployment-url>. Look for an import error (missing dependency) or a template error.- If the last deploy caused it, roll back (R2). If Vercel itself is down, check vercel-status.com and wait.
- Write a short incident note in the vault session log.
R2. Bad deploy → rollback
vercel rollback(choose the previous production deployment), orvercel promote <previous-deployment-url>.- Check:
curl https://phonebazaar.tehchand.com/healthzreturnsok. - Fix forward on a branch, run
pytest, then publish again.
R3. Spike in 500s
vercel logs phonebazaar.tehchand.com --since 30mand group by route.- A template error is usually a missing context key, so reproduce locally with the same URL.
UnicodeEncodeErrorin a header means a toast was built without_toast(); route it through the helper.sqlite3.OperationalError: no such table: a cold start raced the seed. It self-heals on the next request; if it persists, redeploy.
R4. Slow pages
- Cold starts add about 1 s on the first request. That is expected on serverless.
- If warm requests are slow, the catalog query is the hot path. Indexes are not needed at 24 phones. At 1,000+ phones, add indexes on
brandandprice_pence, or move to Postgres.
R5. Admin locked out / password leak suspected
- Generate a new value in-process and set it with
vercel env rm ADMIN_PASSWORD productionthenvercel env add ADMIN_PASSWORD production, piping the value in. Do not echo it. - Update
PHONEBAZAAR_ADMIN_PASSWORDin the private keys file. - Rotate
SESSION_SECRETthe same way to kill existing admin sessions, then redeploy (vercel --prod).
R6. Connect GitHub → Vercel auto-deploys (one-time, pending)
vercel git connect failed with "add a Login Connection to your GitHub account first". To fix it: Vercel dashboard → Account Settings → Authentication → connect GitHub (account shafialtn), then run vercel git connect in the repo. After that, pushes to main deploy to production and PRs get preview URLs.
4. Backup & restore
- Code + catalog + docs: git (
shafialtn/phonebazaar). Restore = clone +vercel --prod. - Orders (demo): not backed up; they reset on cold start. That is documented in the UI and the dev notes.
- Phase 2 (Postgres): daily automatic backups with 7-day PITR. Restore drill once per quarter: restore to a branch database, point a preview deployment at it, and check
/admin/orders.
5. Cost
| Item | Monthly |
|---|---|
| Vercel (Hobby/Pro, low traffic) | £0-£16 |
| Domain (tehchand.com, already owned) | £0 extra |
| Uptime monitor (free tier) | £0 |
| Total (demo) | £0-£16 |
6. Phase 2 ops checklist
- [ ] Connect the Vercel ↔ GitHub login (R6) for auto-deploys and PR previews
- [ ] Managed Postgres; load
DATABASE_URLfrom the Vercel env at runtime; migratedb.py - [ ] Sentry DSN env var + FastAPI integration
- [ ] Admin login rate limiting + CSRF tokens on POST forms
- [ ] Uptime monitor on
/healthzwith alerting to the owner - [ ] Stripe keys (test mode) as env vars; webhook endpoint with signature check