Rzemiosło · The Craft
What is The CraftLevelsGet startedChapters Search Download PLEN
Rules of chapter 14
Level 3 · Codex Chapter deep-dive

In the core the rules are short and hard. Here is what stands behind them: the why, examples and stories from real projects. Rule quotes come straight from the core.

14 — Operational resilience

Chapters 03–05 look after the code and the 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 →. Chapter 14 starts after the deploy — when real users and independent systems hit a running service. The network drops, the provider blocks ports, a 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 → dies halfway, and 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 → charges on every call. These lessons were paid for dearly: almost every one is a 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 → incident, not theory. The common denominator: the worst bugs don’t shout — they quietly hang, log everyone out or drain the budget. Below is what stands behind the rules.

One error doesn’t take everyone down

One bad request degrades that request, not the service: ↗

In Node.js — A runtime that runs JavaScript on the server, not just in the browser. When the site is already in JavaScript, one language on server and browser keeps the project simple. more in the glossary → an unhandled error in an async function can end the whole server process — and the process manager restarts it in a loop, so for a while the site is down for everyone. The safety net has three layers: process-level global error catchers (they log and shut down in a controlled way instead of leaving a “zombie”), a wrapper for async routes that passes the error on instead of losing it, and a 500 page that doesn’t show users technical details (a stack trace is a map of your code for an attacker, 09).

The other half of the rule is edge data. As long as you test on your own account, everything has a password and filled-in fields. Real users bring an account logged in through Google with no password, a null field where the code assumes text — and it often only surfaces after Database swap — Replacing the whole production database with a new version, carrying over user accounts and data. The hardest operation in The Craft — it has its own runbook and needs explicit consent. more in the glossary → in the production database (19). Every such case gets a regression test (03).

Long jobs survive a crash

Long jobs are resumable: ↗

A scraper written as “collect everything, save at the end” loses 100% of its work on every crash — after six hours and one dropped connection it starts from zero. The resilient version records a list of finished units (e.g. processed URLs), saves results every N items and is 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 → (04): a restart picks the work up where it stopped, and a crash costs the last batch, not the whole run.

Match the runner to the job’s lifetime: ↗

A task started in the assistant session’s background runs between messages and reports when it’s done — great for a build or tests (16). But it dies together with the session: closing the conversation or restarting the environment kills the process halfway. It looks like a mysterious failure (often mistaken for anti-bot blocking), but it’s just a disappearing “runner”. Anything that must outlive the conversation — a nightly import, an hours-long scrape — runs as a process detached from the session or as an OS scheduler task.

Other people’s systems are unreliable

External sources are hostile: ↗

Other people’s APIs and sites drop connections, limit request rates (code 429) and — sneakiest of all — return a 200 code with an error page inside. So:

  • 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. Without one, a connection can hang forever — not an error, just silence nobody notices.
  • Retries with a growing gap (e.g. 10, 20, 30 seconds) and a cap on attempts — so a momentary problem doesn’t end in failure, and a permanent one doesn’t end in an infinite loop.
  • Check the content, not the response code. “200 + an error page” is a failure; only the shape of the data tells you whether you got what you came for.

For bulk fetching, rotation helps too: a new session (a fresh connection and cookies) every batch and a browser header from a pool of real browsers — some services cut the connection after a few hundred requests from one session (15).

The provider’s infrastructure has its own rules

The provider’s network breaks working code only in prod: ↗

Locally, sending email works. On the server it hangs. The reason: the hosting provider blocks outbound port 465 (encrypted 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 →). With secure: true on a blocked port every send hangs until the timeout, and the sign-up page “thinks” forever. The fix: port 587 with STARTTLS and hard connection timeouts, so the error is loud rather than silent.

The second email lesson: “sent” isn’t “delivered”. Mail without a 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 DKIM records) lands in spam or nowhere. So a real test send to a real inbox — checked at the provider, in production or Preprod (staging) — A faithful copy of production with no real users, where you rehearse a deploy. A migration that fails on preprod is an ordinary Tuesday; in production it’s an incident. more in the glossary →, because the local network doesn’t have those blocks (03).

Every paid resource sits behind a hard quota ↗

An Endpoint — A single “address” in an API you send a request to for a specific thing (e.g. the list of orders). Apps talk through endpoints — one endpoint = one function you expose. more in the glossary → calling a paid API — a LLM (language model) — An AI model trained on huge amounts of text that understands and generates language — e.g. Claude. Great with unstructured text, but more expensive and less predictable than ordinary code. more in the glossary →, geocoding, email delivery — with no limit is an open tab. One script in a loop (malicious or simply buggy) is enough to wake up to an invoice for thousands of calls. The quota is counted per user and per account tier (free versus paid), enforced on the server (a limit in the interface can be bypassed) and communicated honestly: “you’ve used 20 of 20 questions this month, the limit resets on 1 December” — with the date given up front, not only once you’re blocked (09).

Knowing production is alive

Know prod is alive: ↗

The previous rules keep production from dying; this one tells you it’s alive — before a user writes in. You can start with a small set that delivers most of the value:

  • Logs with levels (error/warn/info, not print everywhere), with context (request id, what failed) — but no secrets and 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 →, because a log shipped to an external tool then becomes a leak. They get searched at 2 a.m., so make them easy to search.
  • /healthz — an address returning 200 after a cheap check (database reachable, version), for the uptime monitor.
  • An external uptime ping — it tells you about an outage before a customer does.
  • Alerts on what hurts, not on noise: a spike in 5xx errors, failed payments and emails, a job that didn’t start. One working alert is worth more than a hundred dashboards nobody looks at.

Recurring jobs: look at the data

Recurring jobs: watch the result, not the runner. ↗

A nightly job is the part of production that by design fails quietly — nobody watches at 4 a.m., and a failure looks exactly like a calm night. Exit code 0, a log that grew, “26 scrapers, 0 errors” — each of those can be true while the data sits frozen.

In the reference project a green nightly report ran for three days next to 44% of the catalogue frozen. The report didn’t lie — it simply knew nothing about a second data path that ran elsewhere. So the Watchdog — An independent monitor that checks by itself whether data is fresh / the app is alive, and alarms when something stalls. For cyclical jobs measure the effect (age of the freshest record), not the job’s exit code — a green report can lie. more in the glossary → checks the age of the newest record for each source (MAX(updated_at) grouped by shop or feed). That measurement catches a job that started and fetched nothing, a write that failed after a successful fetch, and a source added next month — which no log scan will catch. A green report covers only what it knows about; its silence about another path isn’t good news.

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 → ↗

That incident wasn’t a code bug. The OS scheduler task had “run as soon as possible after a missed start” switched off and “don’t start on battery” switched on — so a sleeping laptop meant a skipped night that nobody ever re-ran. No test, code review or git history will catch it, because those settings aren’t in the repository at all. So they go 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 → (retry after a miss, power and network conditions, the account, the working directory) and get checked after every OS, hardware or account change.

Every incident becomes a dated, numbered lesson in the runbook ↗

All the rules above came about the same way: incident → lesson recorded with a date and a number → rule. The runbook is the memory of outages, independent of anyone’s head or the length of a conversation with the assistant (05).