14 — Operational resilience and external dependencies
Commandments III, V, VI at runtime: Environment (dev / prod) — Separate places where the app runs: “dev” for safe tests, “prod” for real users. Dev is a playground, prod is where real users are — the rules for each are completely different. more in the glossary → lives in an unreliable world. The worst bugs don’t shout — they hang, log everyone out, or drain the budget. Almost every rule here was paid for by an incident.
Rules
- One bad request degrades that request, not the service: process-level catchers for unhandled
rejections/exceptions, async routes that forward errors, a 500 handler that leaks no stack trace. Defend
against real edge data (an OAuth account without a password,
nullwhere a string is assumed). - Long jobs are resumable: checkpoint completed units, save every N, Idempotency — A property of an operation you can run many times with the same result — no duplication. Key for scripts and events: a re-run doesn’t break data. Like an “ON” switch. more in the glossary → end-to-end — a crash costs the last batch, not the run.
- Match the runner to the job’s lifetime: the agent’s background survives turns but dies with the session; anything that must outlive the conversation runs as a detached process or OS-scheduled task.
- External sources are hostile: a Timeout — The maximum time to wait for a response — after it the request fails instead of waiting forever. Without it one slow service can quietly hang the whole app. more in the glossary → on every call, retry with exponential backoff and a cap, and validate the response, not the status — “200 + an error page” is a failure.
- The provider’s network breaks working code only in prod: e.g. outbound SMTP / STARTTLS — SMTP is the protocol for sending email; STARTTLS switches on encryption within it (usually on port 587). A wrong port or no timeout can hang every send — and sign-up with it. more in the glossary → 465 blocked → use 587 + STARTTLS with hard connect/greeting timeouts. “Sent” ≠ delivered: verified sender domain (SPF / DKIM — Entries in a domain’s DNS that confirm to mail providers that an email really came from your domain. Without them your app’s emails land in spam or nowhere — “sent” isn’t “delivered”. more in the glossary →) and a real test send. Verify on the provider, not locally.
- Every paid resource sits behind a hard quota — per user and tier, enforced server-side, with a clear message and the reset date shown up front.
- Know prod is alive: structured logs with levels (no secrets, no full PII (personal data) — Information that identifies a person: name, email, address, phone number. They need special protection (GDPR) — they mustn’t end up in logs or on test servers. more in the glossary →),
/healthz, an external uptime ping, alerts on what hurts (5xx spikes, failed payments/mail, a job that didn’t run), errors routed somewhere you’ll see them. - Recurring jobs: watch the result, not the runner. Assert on the age of the freshest record per
source (
MAX(updated_at)grouped by source), not on an exit code — a green report once ran for three days beside 44% of the data frozen. A report covers only the paths it knows about. - Scheduler settings are production and live outside the Repository (repo) — A store of the whole project’s code together with its full history of changes — who changed what and when. The repo is the project’s memory: code, documentation and change history in one place. more in the glossary → (retry after a missed start, power and network conditions, account, working directory) — write them into the Runbook — A written step-by-step guide for production operations, with numbered lessons from incidents. The memory of outages can’t live in someone’s head — the next deploy starts by reading the runbook. more in the glossary → and re-check after any OS, hardware or account change.
- Every incident becomes a dated, numbered lesson in the runbook (→ 05).
Anti-patterns
- 🚫 No global error catcher — one bad request restarts the service for everyone.
- 🚫 A long Scraping — Automatically gathering data from websites with a program instead of copying by hand. Powerful for acquiring data, but it needs manners: respect others’ rules (robots.txt), don’t overload the server. more in the glossary → without checkpoints, run from the session background.
- 🚫 An external call without timeout and backoff.
- 🚫 A paid API — An agreed way for two programs to talk to each other — one asks, the other answers in a set format. Through an API your app connects to outside services (payments, maps, AI). Treat an API key like a password. more in the glossary → without a quota.
- 🚫 Sessions in process memory — every Deploy — Releasing a new version of the app “live”, where real people use it. It’s the moment a change reaches real people — which is why it happens only on an explicit “deploy”. more in the glossary → logs everyone out.
- 🚫 A recurring job watched by its own exit code.
- 🚫 Secrets or PII in logs.