Spanner migrations: Automating dual-write with Antigravity CLI for minimal disruption
Google’s Finance Engineering team automated Spanner migrations using Antigravity CLI to refactor dual-write logic across dozens of DAOs without downtime, reducing manual effort and maintaining data parity.
Google’s Finance Engineering team faced a challenge modernizing their legacy data layer by migrating to Spanner, a globally distributed database, without disrupting production services. Manual rewrites of dual-write logic across dozens of Data Access Objects (DAOs) were slow and error-prone, requiring multi-phase architectures to avoid downtime. To address this, the team developed an automated refactoring pipeline using Antigravity CLI in headless mode, accelerating migration velocity while ensuring data parity in staging environments before production deployment.
The migration required maintaining identical writes to both the legacy datastore and Spanner during the transition, including historical backfill and dual-write implementations. Automated API verification and parity checking were essential to confirm byte-for-byte equivalence across both stores. Each DAO needed unit tests verifying writes to both systems, a task that would have taken months if done manually across 30+ DAOs.
To streamline the process, the team standardized DAO refactoring around a decoupled MutationConverter interface, isolating Spanner schema translation from core business logic. This created a deterministic contract between the DAO and Spanner SDK, enabling reliable AI-generated code. The approach reduced manual effort by automating systematic, multi-file updates across the codebase.
The team built an orchestration script, migration_ui.py, to run Antigravity CLI in headless mode, integrating it with continuous integration pipelines. The script executed batch refactoring, generated unit tests, and validated changes via automated testing. Engineers could queue up to 10 DAOs overnight, receiving validated changelists for review by morning, significantly reducing migration effort and improving data fidelity.