{
  "version": "2",
  "id": "https://freelancenews.online/news/developer-post-outlines-expand-and-contract-pattern-for-zero-downtime-1446fce3",
  "title": "Developer Post Outlines Expand-and-Contract Pattern for Zero-Downtime Database Migrations",
  "summary": "A dev.to contributor argues that bundling schema changes, code deploys and data backfills into one step breaks rolling deployments, and describes a three-phase alternative plus moving migrations out of container startup.",
  "body": "A community post published on dev.to by a contributor writing as Tanmay sets out a design pattern for changing database schemas without taking an application offline. The piece is an instructional article rather than a product release or a report of a specific incident, so its claims should be read as one developer's stated approach rather than independently verified findings.\n\nThe author's central argument is that most migration failures stem from trying to do too much at once. In the described failure mode, a developer alters a column, deploys new application code immediately afterward and runs a backfill script against the live database, all as a single deployment step. The post says this breaks in environments using rolling updates, Kubernetes pods or serverless instances, because old and new application versions run concurrently during rollout.\n\nThe stated consequence is concrete: if the new version renames or drops a column, the old version still expecting the previous schema crashes, and if a backfill locks a large table the API can hang. The author describes the typical outcome as an emergency rollback and a database left corrupted or only half-migrated. These are the author's characterizations of a common failure pattern, not measurements from a named incident.\n\nThe proposed remedy is the Expand-and-Contract pattern, which the post also calls Parallel Change. Its governing rule, as stated, is that old and new application versions must always be able to run at the same time without error. Rather than one deployment, the author splits the work into three phases.\n\nIn the first phase, called Expand, the schema is modified by adding new columns or tables alongside existing ones. The post explicitly warns against deleting, renaming or adding NOT NULL constraints without defaults to existing fields at this stage, and gives an example of adding a nullable full_name column to a users table while existing instances continue reading and writing first_name and last_name. The author says this database change is invisible to live traffic.\n\nThe second phase involves deploying application code that writes to both old and new columns on create and update, then backfilling historical records. The post is emphatic that a single massive UPDATE statement on a large table should not be run in production because of lock contention. Instead it supplies a sample script that selects a limited batch of rows where the new column is null, updates only those rows, stops when no rows remain and sleeps briefly between batches to throttle I/O.\n\nThe third phase, Switch and Contract, begins once historical data is backfilled and both fields stay in sync. The author lists the sequence: deploy code that reads from the new column while continuing to write to both, verify that old application instances are fully decommissioned, remove references to the old columns from the codebase, and only then run a cleanup migration to drop the old fields. The example drop statements are marked as safe only after no active code touches those columns.\n\nA second operational recommendation concerns where migrations run. The post identifies executing migrations inside an application startup command, such as a Docker container's ENTRYPOINT or CMD, as a common mistake. When services scale horizontally, every container booting at the same time attempts the schema change simultaneously, which the author says leads to race conditions, deadlocks and failed container boots.\n\nThe alternative offered is to run migrations as a dedicated, single-execution step in the CI/CD pipeline before new application containers deploy, so schema adjustments happen sequentially in a controlled environment. The author concludes that combining the pattern with isolated deployment steps turns schema changes from high-risk production events into routine background updates.\n\nFor freelancers and developers maintaining client applications, the practical value lies in the sequencing discipline rather than any tooling. The post names no specific migration framework, database engine beyond SQL-flavored examples, or CI/CD vendor, so the guidance is portable but also untested in any environment the author documents. A contractor inheriting a codebase that runs migrations at container startup would need to verify how their pipeline is structured before adopting the recommendation.\n\nThe tradeoffs are implicit in the described process. Splitting a change into three deployments means more coordination steps and a period during which both old and new columns exist and must be kept in sync, which the author acknowledges by requiring dual writes. The batch backfill also takes longer than a single statement by design, trading speed for reduced lock contention.\n\nWhat remains unknown is substantial. The post offers no measurements of downtime, lock duration or backfill throughput, no named case study and no discussion of rollback strategy if the switch phase fails partway. It also does not address databases or deployment models where the pattern may be harder to apply. Readers should treat the recommendations as a reasoned checklist from a practitioner, not as validated benchmarks.\n\nThe useful conclusion is that the article's core rule, keeping old and new application versions mutually compatible during rollout, is a testable design constraint that teams can check against their own deployment process. Whether the three-phase structure fits a given project depends on factors the post does not examine, including team size, release cadence and the specific database's locking behavior.",
  "category": "dev",
  "language": "en",
  "datePublished": "2026-11-25T09:17:49.596Z",
  "dateModified": "2026-11-25T09:17:49.596Z",
  "eventDate": null,
  "sourcePublicationDate": "2026-11-25T09:03:13.000Z",
  "source": {
    "name": "dev.to",
    "url": "https://dev.to/tanmay2627/how-to-run-zero-downtime-database-migrations-2oc0",
    "kind": "community"
  },
  "practicalImpact": "Editorial interpretation: freelancers and developers can use the post's compatibility rule as a checklist for client deployments, verifying whether migrations run at container startup and whether old and new app versions can coexist during rollout. The article names no specific tools, so applying it requires mapping the three phases onto whatever migration framework and pipeline the project already uses.",
  "limitations": "This is a community instructional post, not a verified incident report or benchmark. It provides no downtime, lock-duration or throughput measurements, no named case study, no discussion of rollback if the switch phase fails, and no tooling or database-specific guidance. Claims about failure modes are the author's characterizations.",
  "keyPoints": [
    "The author argues that combining schema changes, code deployment and backfill in one step breaks rolling, Kubernetes and serverless deployments where old and new app versions run concurrently.",
    "The Expand-and-Contract pattern splits a change into adding nullable columns, dual-writing with batched backfills, then switching reads and dropping old fields only after old instances are gone.",
    "The post warns against single massive UPDATE statements on large tables and provides a throttled batch script as an alternative.",
    "It also recommends running migrations as a dedicated CI/CD step rather than inside container startup commands, to avoid simultaneous schema changes across scaled instances.",
    "No measurements, named case studies or tooling specifics are provided; the guidance is a practitioner's stated approach."
  ],
  "review": {
    "status": "source-reviewed",
    "checkedAt": "2026-11-25T09:17:49.596Z",
    "method": "Automated comparison against retrieved source text; not independent fact-checking.",
    "correctionNote": null
  },
  "sources": [
    {
      "id": 1,
      "url": "https://dev.to/tanmay2627/how-to-run-zero-downtime-database-migrations-2oc0",
      "publisher": "dev.to",
      "title": "How to Run Zero-Downtime Database Migrations",
      "publishedAt": 1795597393000,
      "fetchedAt": 1795598256288,
      "hash": "c0750aecff1815935eb901aa64fc210830cb27fd176709ede17126789aca61f9",
      "kind": "community"
    }
  ],
  "claims": [
    {
      "claim": "The author says bundling schema changes, code deploys and backfills into one step breaks rolling, Kubernetes and serverless deployments because old and new app versions run concurrently.",
      "source": 1,
      "id": "claim-1",
      "url": "https://freelancenews.online/news/developer-post-outlines-expand-and-contract-pattern-for-zero-downtime-1446fce3#claim-1"
    },
    {
      "claim": "The post states the Expand-and-Contract pattern requires old and new application versions to run simultaneously without error.",
      "source": 1,
      "id": "claim-2",
      "url": "https://freelancenews.online/news/developer-post-outlines-expand-and-contract-pattern-for-zero-downtime-1446fce3#claim-2"
    },
    {
      "claim": "The author warns against deleting, renaming or adding NOT NULL constraints without defaults during the expand phase.",
      "source": 1,
      "id": "claim-3",
      "url": "https://freelancenews.online/news/developer-post-outlines-expand-and-contract-pattern-for-zero-downtime-1446fce3#claim-3"
    },
    {
      "claim": "The post advises against a single massive UPDATE on large tables and instead recommends small background batches to avoid lock contention.",
      "source": 1,
      "id": "claim-4",
      "url": "https://freelancenews.online/news/developer-post-outlines-expand-and-contract-pattern-for-zero-downtime-1446fce3#claim-4"
    },
    {
      "claim": "The author identifies running migrations inside container startup commands as a mistake that causes race conditions and deadlocks when services scale horizontally.",
      "source": 1,
      "id": "claim-5",
      "url": "https://freelancenews.online/news/developer-post-outlines-expand-and-contract-pattern-for-zero-downtime-1446fce3#claim-5"
    },
    {
      "claim": "The post recommends executing migrations as a dedicated single-execution CI/CD step before deploying new containers.",
      "source": 1,
      "id": "claim-6",
      "url": "https://freelancenews.online/news/developer-post-outlines-expand-and-contract-pattern-for-zero-downtime-1446fce3#claim-6"
    }
  ],
  "formats": {
    "html": "https://freelancenews.online/news/developer-post-outlines-expand-and-contract-pattern-for-zero-downtime-1446fce3",
    "markdown": "https://freelancenews.online/news/developer-post-outlines-expand-and-contract-pattern-for-zero-downtime-1446fce3.md",
    "json": "https://freelancenews.online/news/developer-post-outlines-expand-and-contract-pattern-for-zero-downtime-1446fce3.json"
  }
}