Video in progress

How do you move a table shared by two services to the ownership of a single service with zero downtime?

Step by step: first I switch the second service from writing directly to writing through an API, then reads too. If needed I move the data to the new DB with dual writes or CDC and verify by comparing. Each step must be a separate deploy and reversible.

📖 Answer

The situation: the billing and subscription services both write to one subscriptions table. subscription should be the owner.

Step 1: name the owner and centralize writes. I add the operations billing needs to the subscription API (for example POST /subscriptions/{id}/renew). billing no longer writes to the table, it calls the API. Behind a feature flag, because this is the riskiest step: I enable it first on low traffic and check the invariants.

Step 2: move reads. For the data billing needs there are two options: the API, or a local copy built from SubscriptionChanged events. If billing reads thousands of rows overnight, the local copy is better.

Step 3: close the permissions. I remove billing's DB login permission on the table. Any leftover access nobody knew about (an old reporting script, a forgotten batch job) shows up right here, so I watch the audit log for a week first.

Step 4 (if needed): the physical move to a separate DB. Options:

  • a stream from the old table to the new one with CDC (Debezium), then a cutover in a short "writes paused" window;
  • or dual write inside the service: write to the old and the new place, "shadow" read from the new one and log the differences, then switch reads to the new one.

At each step a comparison script runs: row counts, sums, hashes over random samples. When moving data, the feeling that "it seems to have worked" is the most dangerous thing.

The whole process can stretch over several weeks, and that is normal. Cramming every step into one release to go faster means losing the ability to roll back.