Database Migration Strategies — concept page covering online schema change (gh-ost, pt-online-schema-change), expand-contract pattern, dual-write Mongo→Postgres replatform with CDC, and big bang vs incremental migration tradeoffs. Four scenarios + 2 ADRs (online vs maintenance window, gh-ost vs pt-osc vs pg_repack).
Zero-downtime migration — это протокол изменения ownership, а не один SQL script. Главные риски: DDL lock, race backfill/online writes, dual-write divergence, stale router и rollback после несовместимого contract.
| Компонент | Ответственность |
|---|---|
| Version-Tolerant Application | Работает со старой и новой schema в expand window. |
| Versioned Write Router | Выбирает единственный authoritative writer по migration epoch. |
| Source Database | Остаётся source of truth до fenced cutover. |
| WAL or CDC Position | Несёт committed changes после snapshot position; retention ограничена. |
| Idempotent Backfill | Копирует ranges с checkpoints и conditional upsert. |
| Target Database | Принимает snapshot и ordered changes, но не становится writer преждевременно. |
| Range Validator | Сверяет counts, hashes, invariants и lag перед gate. |
Add nullable/new structures and deploy readers/writers that tolerate both representations before any destructive contract.
Проверяемый исход: Old and new application versions remain valid throughout the rollout window.
The copy records log position P, scans a consistent snapshot, and then applies committed changes after P. A blind table scan followed by listening at current head can miss updates.
Проверяемый исход: Every source mutation is represented by either snapshot state or a later ordered change, with idempotent overlap allowed.
Lag reaches the declared threshold, validators pass, source writes are fenced, and only then does the routing epoch move.
Проверяемый исход: There is never an interval with two unfenced authoritative writers.
If validation fails, routing stays on source. After cutover, rollback is allowed only while schemas, log retention and reverse reconciliation remain compatible.
Проверяемый исход: Failure closes the gate; it does not silently continue with divergent databases.
Числа выше — учебные inputs или размерностные формулы. Их нельзя выдавать за benchmark или SLA конкретного продукта.
Диаграмма показывает причинные границы и recovery contracts, а не скрытую реализацию конкретного managed-сервиса. Любая stronger guarantee действует только в явно названной transaction/checkpoint/acknowledgement boundary.
Введите числа или выберите пресет