Technical document

CI/CD Design for Separating Cloud Run Deployment and DB Migration

When deploying an application to Cloud Run, we organize how to separate Docker builds, service updates, DB migrations, and rollbacks.
CI/CD / Cloud Run~10 minPublication Date September 22, 2026Update date September 22, 2026
CI/CD Design for Separating Cloud Run Deployment and DB Migration

Summary

Key points of this document

  • Where are the design challenges?
  • How to define boundaries
  • Details that matter in implementation

Overview

Cloud Run deployment is simple if it only involves container updates. However, if it includes DB migration, a procedure considering application and data compatibility is required. Mixing Cloud Run deployment and DB migration into the same procedure makes it unclear which to revert in case of failure.

Where are the design challenges?

If service updates and DB changes are executed immediately after building in CI/CD, the state becomes complex in case of mid-process failure. Even if only the new application is reverted, the DB schema might not be reversible.

Cloud Run can revert revisions, but DB changes are not automatically reverted. While multiple instances exist, there's also a period where old and new code access the same DB.

Cloud Run can easily create new revisions, but DB schemas cannot run in parallel like revisions. Even if only the application is reverted, DB changes remain, making it risky to treat deployment and migration as the same unit of success.

How to define boundaries

A safe procedure involves separating compatible schema additions, application deployment, backfilling, constraint additions, and old column deletions into stages. DB migrations should be independent execution units, like Cloud Run Jobs, with logs and exit codes checked.

In design, we separate into expand migration, new app deployment, traffic switching, and contract migration. Using Cloud Run Jobs allows treating migration as an explicit execution unit rather than a side effect of app startup.

Details that matter in implementation

In CI, Docker builds, tests, image pushes, migration job execution, and Cloud Run service updates are explicit steps. Risky migrations are not executed automatically but separated into manual approvals or maintenance procedures.

In CI/CD, after container build, a migration job is created or updated, specifying migration direction and target version with arguments. Application revisions receive traffic after migration completion, and can be reverted to old revisions in case of failure.

  • Do not run automatic migration on app startup; execute it once with Cloud Run Jobs.
  • Save migration history, executor, commit SHA, and execution logs.
  • Destructive changes make old applications unreadable, so separate them into contract migrations of a different release.

Observe how it breaks

In verification, we check for migration failure, service update failure, rollback to old revision, and job re-execution. We use production-equivalent data volume in staging to observe execution time and locks.

In verification, we confirm that traffic does not flow to the new revision upon migration job failure, that the old revision operates with the new DB state, and that re-execution does not break anything. Using production-equivalent data volume in staging also reveals lock times.

Discarded options and tradeoffs

Separating procedures lengthens CI/CD. While it may seem cumbersome for small changes, over-automating irreversible DB changes is riskier. It's realistic to vary the automation level depending on the type of change.

Phased releases increase procedures but make rollback in case of failure more realistic. Batch releases are faster, but recovery becomes difficult if stuck with DB changes. If you want to avoid business interruption, prioritize compatibility over procedure brevity.

Decision criteria for the field

The safety of Cloud Run deployment is not sufficient with revision management alone. Treating DB migration as an independent operational unit makes it easier to make decisions in case of failure.

In Cloud Run's CI/CD, releasing containers and changing data structures should be separated. Jobifying migrations clarifies deployment failure points.

Technical documents

We will continue to increase technical documentation.

We will continue to organize our thoughts on AI, cloud, business app development, requirements definition, and operational design into documents.

Go to technical documentation list