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

12 — Flexibility and scalability

Flexibility is the ability to change without rewriting; scalability, the ability to grow without rebuilding. Both come from the same habits: separated layers, changes by addition, risk hidden behind a switch, as little state in the process as possible. And from one opposite habit: don’t overengineer. A simple architecture you know how to extend beats a distributed one you don’t need. Below is what stands behind the rules.

Boundaries with a contract

Separate the layers by a contract, not by shared code: ↗

In the reference project the data (SQLite — The simplest database — the whole thing lives in one file, with no separate server. A great default to start: zero configuration, easy backup (you copy the file). As you grow, you migrate up. more in the glossary →), data fetching (Python — A popular, readable programming language — The Craft’s default for scripts, data and the back end. A proven default: lots of ready tools and libraries, easy to drive with AI. more in the glossary → scripts) and the website (Node/Express) are three separate worlds. They’re joined by the database schema — a contract (11) — not by shared functions imported from one place. So a fetching script can be swapped or rewritten without touching the website, and vice versa. The same principle works between front end and back end: an explicit 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 → contract (e.g. described in OpenAPI) lets you replace one side without touching the other (08).

It’s also worth thinking boundaries through in advance where the future is visible: if a mobile app is coming in a year, the decisions “sessions or tokens”, “SQLite or PostgreSQL — A solid, “grown-up” database for bigger apps — runs as a separate server. The default step after SQLite, when you need many concurrent users and advanced features. more in the glossary →” are recorded as ADR (decision record) — A short note: what we chose, why, and which alternatives we rejected (Architecture Decision Record). Six months later nobody has to guess whether a decision was deliberate and whether it’s safe to change. more in the glossary → now, rather than discovered in the middle of a rewrite (01).

Changes that don’t break things

Changes are additive and backward-compatible: ↗

A new column, a new 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 →, a new language — everything is added alongside what works instead of replacing it. Old code keeps running on the new schema, the old mobile app keeps talking to the API, and undoing a change doesn’t require undoing the whole world (04). A rewrite from scratch (“big bang”) turns hundreds of small, checkable steps into one enormous one that can’t be tested piece by piece.

Flags — at the right moment

Feature flag — An internal switch that turns a new feature on for some people, or off, without reworking the code. You roll a novelty out gradually and roll it back in a second — the cheapest insurance with any change. more in the glossary → arrive with the first risky change that reaches live users ↗

A feature flag is a switch in the database or configuration: new code goes to 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 → switched off, then gets turned on for some users (e.g. for yourself, then 10%), and finally for everyone. When something goes wrong, switching it off takes a second and needs no 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 →. Without flags every change is “all or nothing”.

Version 1.1.1 clarified the timing: flags aren’t part of day one of a prototype that has no users to protect yet — that would be overhead with no benefit. They arrive with the first risky change for real people, and from then on they may not be skipped. The article “Feature flags in plain words” explains it in plain language.

Less state in the process

Keep the process stateless where you can ↗

If login sessions live in the server process’s memory, every restart logs everyone out, and a second copy of the server can’t run alongside because it doesn’t know the first one’s sessions. State moved to durable storage (a separate file, a database, Redis) lets the process be restarted, deployed without downtime or run in several copies (14).

The platform as a deliberate choice

Platform is a recorded trade-off: ↗

This is a real decision from two projects. Scale-to-zero (e.g. Cloud Run): you pay for usage, no traffic means no cost, but the first request after a pause waits for a “cold start”. Good for uneven, global traffic. An always-on VPS — A rented piece of a cloud server “just for you”, where you put an app “live”. Predictable cost and full control. One VPS easily carries a few small projects. more in the glossary → (e.g. Hetzner — A cheap, solid server (hosting) provider you put an app “live” on. The codex’s default server choice — predictable cost and performance without overpaying. more in the glossary → with a process manager): a fixed, predictable cost, no cold start, full control, a SQLite database on local disk. Good for predictable traffic. The choice follows the traffic profile and budget, not fashion — and goes into an ADR, so that a year later everyone knows why.

Caches and pipelines

Every Cache — A temporarily remembered result, so the same thing isn’t computed again on every request. Speeds the app up, but can be a trap: a stale cache shows old data. more in the glossary → has explicit invalidation ↗

A cache with no defined lifetime or refresh method is a recipe for showing stale data forever — and for “works for me, not for the customer” bugs. In the reference project: the full data-processing Pipeline — A chain of processing steps run in order, e.g. fetch → clean → enrich → check. When each step runs on its own and repeats safely, a failure halfway doesn’t mean starting from zero. more in the glossary → clears the cache at the end, rankings live in the cache for 10 minutes, and static files carry max-age headers (short in local development, long and immutable in production).

Pipelines are composable 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 →: ↗

A processing pipeline (e.g. normalisation → metadata → enrichment → validation → statistics) is made of stages that can each run on their own, and re-running is safe (04). When the enrichment stage fails halfway, you restart from it, not from the beginning.

Global product = i18n from the first Commit — A saved, labelled point in the project’s history — a confirmation of a specific batch of changes. Small, described commits make a history you can return to any working state from. more in the glossary → ↗

Multilingual support glued on after a year means rewriting every text, every date format and every template. If the product is meant to be global, the translation structure goes in with the first commit — even if it holds only one language at the start (10).

Scale when the numbers say so

Scale by the numbers: ↗

SQLite in WAL — Write-Ahead Log: a database mode where changes go to a journal first, then to the data. Gives safety (recovery after a crash) and better read/write concurrency. more in the glossary → mode and a simple app handle surprisingly heavy traffic — the reference project serves several thousand items without PostgreSQL. Moving SQLite → PostgreSQL or Monolith — An app built as one whole (one deploy, one database), not a patchwork of separate services. A simple, cheap default to start — easy to grasp. You split it only when scale really demands. more in the glossary → → services makes sense when measured latency, cost or data size demand it, and the decision goes into an ADR with those numbers (13). Microservices, a Kafka queue or Kubernetes for a hundred users is upkeep with no gain — and a new class of failures that didn’t exist before.