Your migrations run in an init container and two pods ran them at the same time during a deploy, leaving the schema half-applied. How do you fix the approach?

IntermediateScenarioData and databases
Answer

Situation read → Init containers run once per pod, so with 3 replicas you get 3 concurrent migration runs. Migrations need to run exactly once per release.

What I'd do →

  1. Repair the schema first: check the migration tool's version table (schema_migrations, flyway_schema_history), fix or roll back the partial change manually, and mark the correct state.
  2. Move migrations to a single Kubernetes Job that runs before the Deployment updates: an Argo CD PreSync hook or a Helm pre-upgrade hook.
metadata:
  annotations:
    argocd.argoproj.io/hook: PreSync
    argocd.argoproj.io/hook-delete-policy: BeforeHookCreation
spec:
  backoffLimit: 0
  1. Keep a database lock as a second safety net (Flyway, Liquibase and most tools take an advisory lock).
  2. Make migrations transactional where the database allows it (PostgreSQL supports transactional DDL).
  3. Write migrations to be backward compatible so the old pods keep working while the Job runs.

Why → One Job per release gives exactly-once execution and a clear pass or fail gate before rollout.

Interview tip → Mention backoffLimit: 0; you don't want a failed migration retried automatically.

All Real-World Interview questions Roadmap: Interview readiness

More on Data and databases