{"success":true,"name":"ship-cross-layer-changes-in-safe-order-expand-first-migrate-","description":"A change spans DB, backend, and frontend and must go live without breaking users","category":"ai-brimind","path":"ai-brimind/ship-cross-layer-changes-in-safe-order-expand-first-migrate-/SKILL.md","file":"SKILL.md","content":"---\nname: ship-cross-layer-changes-in-safe-order-expand-first-migrate-\ndescription: \"A change spans DB, backend, and frontend and must go live without breaking users\"\n---\n\n# Ship Cross-Layer Changes in Safe Order: Expand First, Migrate the Middle, Contract Last\n\n## When to use\nYou are deploying a change that touches database shape AND backend AND frontend together, and the plan is to flip everything at once and hope the pieces land simultaneously.\n\n## Example request\nNew required field deployed in backend code before any data migration ran → every request touching old records crashes the moment the deploy lands; the DB and the code disagreed for exactly the window that mattered. Frontend shipped expecting the new response shape while the backend still sends the old → users see broken screens until the second deploy catches up; layers never land at the same instant, so one of them must tolerate both worlds. The safe sequence has a name — expand/contract: ADD the new field/endpoint alongside the old (expand), migrate data and consumers over, then REMOVE the old (contract); at every step, everything running still works. A dev-only project with no users → flip it all at once freely; this ceremony is for changes landing under live traffic.\n\n## Instructions\nAct as a release engineer who knows the physics of deployment: database, backend, and frontend NEVER change at the same instant — there is always a window where old code meets new data, or new frontend meets old backend, and whatever breaks in that window breaks in production, in front of users — so cross-layer changes are sequenced so that EVERY intermediate combination still works. This is the expand/migrate/contract pattern, and it is the named, standard answer. Do this: (1) Before deploying, enumerate the combinations the rollout will pass through: old backend + new DB shape? new backend + old frontend still cached in users' browsers? For each pair, answer 'does it work?' — any 'no' means the plan ships a breakage window on purpose. (2) EXPAND first, breaking nothing: add the new column/field as optional with a default, add the new endpoint or new response field ALONGSIDE the old one — additive changes are the only kind that is always safe to deploy first, which is exactly your API-evolution discipline extended to the database. Deploy this; the world is unchanged but the new landing zone exists. (3) MIGRATE the middle deliberately: run the data migration (with your backup-first and re-runnable habits), move the backend to write both shapes or the new one while still READING both, then ship the frontend that consumes the new shape — old cached frontends keep working against the still-present old shape, because browsers hold old bundles for hours and you do not control when users refresh. (4) CONTRACT only after evidence: when logs/metrics show nothing calls the old endpoint and no code reads the old field (grep + your monitoring, not optimism), remove the old shape in a final, boring deploy. Rushing the contract step is how 'that field nobody uses' takes down the one cron job everyone forgot. (5) Keep each deploy individually reversible per your reversible-steps discipline — small steps that can roll back beat one heroic flip that cannot. Only execute once you can state, for every moment of the rollout, which versions coexist and why each pairing survives — 'we'll deploy everything quickly' is not a sequence, it is a countdown to the window where quickly wasn't quick enough.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #238\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}