Rzemiosło · The Craft
What is The CraftLevelsGet startedChapters Search Download PLEN
Rules of chapter 18
Level 2 · Technical 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.

18 — Release rehearsal

A Migration (database) — A controlled change to the database layout — adding a column, a table or moving data — step by step. Like a renovation to plan: rebuilding data in a set order so nothing “collapses”. more in the glossary → or 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 → run for the first time in 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 → Maintenance window — A short, planned period when users see a “work in progress” page while the database or configuration changes behind it. It guarantees the app never runs, even briefly, on half-changed data. more in the glossary → is being tested on your users. Chapter 18 (split out of the old chapter 05 in 1.1.1) describes the cure: a rung between your laptop and production — 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 →, a faithful copy of production on which you run exactly the same 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 → scenario once, before doing it for real. Below is what stands behind the rules.

Why a third environment

Each of the three environments has one job. Dev, your computer, is for building and reproducing bugs — on test data, or on an anonymised copy of production when a bug only shows up with real data shapes. Prod serves users and is sacred: it’s touched only on an explicit “deploy” and only with steps rehearsed the same day. Preprod is a server-side clone of production — the same operating system, web server, process manager and certificates — but with no live users, behind a password (basic-auth) and barred from indexing. Its only job is rehearsing the migration and the deploy itself.

Preprod isn’t needed from day one. You add it when the project reaches the third rung of branching (more people or parallel streams of work) or at the first genuinely risky migration (05). Before that it’s overhead with no benefit.

The same copy, every time

Build preprod from prod the same way every time — scripted: ↗

A hand-built preprod differs from production after a month in ten little details nobody remembers — and the rehearsal stops proving anything. So building preprod is a script (04): a clone of 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 → with production’s deploy key (access to the private repository without creating new credentials), a database refresh from production’s Backup — A copy of your data saved earlier, which you return to when something goes wrong. It’s the only way to undo a change to data — code comes back from git, data only from a backup. more in the glossary →, the same steps every time.

anonymise 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 → before it leaves prod ↗

A copy of the database on preprod is a second copy of responsibility for personal data — on a server usually less well guarded than production. So anonymisation (emails, names replaced with placeholder values) happens before the data leaves production, not “later, on preprod”. A non-production server never holds real user data (09).

A preprod that doesn’t pose as production to the outside world

Environment-specific values are env-overridable, never hard-coded: ↗

A hard-coded site address, Canonical — A tag that tells search engines which address is “the real one” for a piece of content. It prevents duplicates (e.g. the same product under several addresses) that split your Google ranking. more in the glossary →, link preview (Open Graph (OG) — Tags that decide how a link looks when pasted into Facebook, LinkedIn or a messenger (image, title, description). A good link card means more clicks — a bad one can show what you don’t want (e.g. a price). more in the glossary →) and Sitemap — A file listing every address of the site, helping search engines find them. New pages reach search engines faster, and language versions get linked together. more in the glossary → make preprod send production links out into the world — or, worse, get indexed by search engines as a duplicate of production. All these values come from environment variables, and preprod gets its own (10). This website does the same with Search Console verification and analytics — empty variables mean no tags.

A rehearsal for real

Rehearse the real 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 →, not a simplified one: ↗

A simplified version (“I’ll just run the migration”) checks the migration but not the deploy. A rehearsal is the whole scenario: switching on the maintenance page, pulling the code, stopping the process, the backup, the migration, the start, the Smoke test — A quick “does it even work” test right after a deploy — checks the most important paths (e.g. login). Catches disasters in 30 seconds before a user sees them. A cheap way to sleep well after a deploy. more in the glossary →, switching maintenance off. Along the way you measure the window — so you know whether users will see the maintenance page for 15 seconds or 15 minutes. And you confirm the migration is forward-only and 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 →: running it a second time breaks nothing (04). A migration that fails on preprod is an ordinary Tuesday. The same failure in production is an incident, with users staring at a 503 error.

Expect the gotchas only a real preprod surfaces: ↗

A real preprod has one advantage over a pretend one: problems with the infrastructure itself show up on it. Two examples from the reference project: automatic Let’s Encrypt certificate renewal checks the domain through a special address (http-01) that has to bypass the preprod password — otherwise renewal fails with a 401 error and three months later the certificate expires. A private repository needs SSH — An encrypted connection to a server for sending it commands and transferring files. An SSH key is access to production — guard it like your most important password. more in the glossary → access configured before the first code pull. Better to run into such things on a server nobody uses than to discover them in the middle of a deploy.

A rehearsal stage, not a second prod

Preprod is a rehearsal stage, never a second prod: ↗

Preprod has no live users, so a stale or anonymised database is fine. But its database is never moved back to production. The moment data from preprod becomes a source of truth (“I fixed it on preprod, I’ll move it over”), a second source of truth appears that has to be kept in sync — and anonymised preprod data would replace real accounts (11). Data flows in one direction only: from production to preprod.

A database swap that preserves user accounts — the hardest operation in this doctrine — has its own runbook in chapter 19. Preprod is where you rehearse it.