How do I change the design without an outage?
You will learn: step by step plans for four common changes, how to check each one worked, and the way back if it did not.
Most designs change after launch. These four changes come up in almost every growing system. Each plan ends with the way back, because a migration without one is a bet.
Change data capture streams every committed change out of the database, so search indexes, caches and warehouses can follow it without polling or scanning the primary.
Change data capture, in four steps
Teal: the source of truth. Orange: the thing to watch.
The way back. Drop the replication slot or stop reading the binlog. The source database is unchanged, so turning CDC off is safe, as long as the slot is dropped and does not keep holding WAL.
One database often holds several domains (orders, users, catalog). Splitting one out gives it its own scaling, its own failure domain and its own team.
Splitting one database into two
The old tables stay read-only until you are sure.
The way back. Until the old tables are dropped, switch writes back and copy the new rows in the other direction. Decide in advance how long this window stays open.
The engines speak similar SQL, so most of the work is in the details that differ.
MySQL to PostgreSQL
Rehearse steps 2 to 4 on a copy, and time them.
The way back. Keep MySQL receiving the changes from PostgreSQL for a while after cutover, if your tooling supports reverse sync. If not, the way back is a restore, so rehearse it.
A cache helps when the same data is read far more often than it changes. Added carelessly, it serves stale data and can take the database down when it empties.
Adding a cache, safely
Four situations the design has to handle before launch.
The way back. Turn the cache off with a flag. If the database cannot take the load without it, the cache has become part of capacity, and the design should say so.
These incidents are why the choices below matter. Each one is written up with its numbers and sources.
You are moving a 2 TB MySQL database to a new cluster with under a minute of write downtime. Outline the steps.
Write your answer down first. Then open mine.
Copy: a physical copy, such as XtraBackup or a cloned replica, restored on the new cluster. Note its GTID position.
Catch up: make the new cluster a replica of the old one from that position. Let it catch up, then compare the data with checksums (pt-table-checksum or similar). Send some read traffic to it and compare answers.
Cut over: set the old primary super_read_only, wait until the new one has applied every GTID, then switch the application through the proxy or DNS you lowered the TTL on beforehand. Writes are paused only for those seconds. If any superuser application connection exists, revoke its write grants first, since read_only does not stop a superuser.
Keep a way back: replicate from the new cluster to the old one for a while, so rolling back is another switch, not a restore.
How do I run it in production? What to check when it is slow or broken, where it runs and what it costs, how big it must be, pooling, backups, security, upgrades and other changes made safely.