Resharding MySQL with Vitess vreplication: move tables while traffic runs
Move tables between MySQL shards in Vitess without stopping reads, then cut over writes with a controlled window. Check lag first.
16 Jul 2026, 19:45 UTC

The problem: a single shard cannot absorb the growth
Your production MySQL shard is approaching disk and query limits, but the application cannot afford a maintenance window long enough to export and import terabytes of data. You need to split the shard or move hot tables to new hardware while reads and writes keep arriving. Vitess addresses this by separating the query layer from the storage layer: VTGate routes SQL to the right MySQL shard, and vreplication continuously copies rows from source to target in the background.
How vreplication fits a resharding job
Vitess organizes data into keyspaces and shards. A keyspace is a logical database, and a shard is a MySQL instance that owns a range of keyspace IDs or a table in a vertical split. Vreplication is Vitess's built-in replication mechanism: it reads changes from the source shard and applies them to the target shard, while VTGate continues to use the VSchema—the routing map that tells Vitess which shard owns which data.
During a reshard, rows flow to the target while the source still handles traffic. Once the target catches up, a cutover updates the VSchema so new writes go to the target. Before cutover, you can pause, resume, or reverse the job, which limits the blast radius of a misconfiguration.
Worked example: move one table in staging
Do not try this on production first. Pick a small, non-critical table in a staging keyspace, for example customer_preferences in keyspace customer_keyspace. You will need Vitess administrative access to run vtctl against the cluster, and MySQL access to the Vitess metadata database to inspect vreplication state.
Run shard health checks from the Vitess control host or any machine with vtctl configured:
vtctl ShowShard customer_keyspace/0
Look for the source and target shard tablets in the output. If a tablet is not SERVING, pause and fix replication before starting the copy.
Start the vreplication stream for the table. Exact subcommand names differ by Vitess major version, so consult your release notes; conceptually the job tells Vitess to copy customer_preferences from shard 0 to shard 1 and keep applying changes.
While the copy runs, check progress from the metadata database:
SELECT * FROM _vt.vreplication WHERE db_name = 'customer_keyspace' AND table_name = 'customer_preferences';
Expected checks: the lag column should trend toward zero as the initial copy finishes, and the error or message column should be empty. If lag grows steadily, the source is under too much load or the target cannot apply changes fast enough.
Risk: the initial copy consumes extra disk, memory, and network on both MySQL instances. Coordinate the job with off-peak traffic if your staging cluster shares hardware with other workloads.
Diagnostic decision: when to cut over
Cutover is the moment VTGate stops sending writes to the old shard and starts sending them to the new one. Do not trigger it based on elapsed time alone. Use these signals:
- Vreplication lag is near zero and stable over several minutes.
- No error rows appear in the vreplication metadata table.
vtctl ShowShardreports both source and target tablets asSERVING.
Plan a brief write pause or redirect during cutover. Vitess can switch routing quickly, but in-flight transactions and application connection pools may need to drain. After cutover, verify reads and writes land on the target by querying a row you just inserted and checking which shard VTGate used.
Limitations and rollback
Resharding changes cluster state, so treat it as a stateful operation. Before final cutover, Vitess supports pausing, resuming, or reversing a vreplication job, which acts as rollback for the copy phase. After cutover, reversing traffic requires a new resharding job back to the original shard or restoring from backup, so confirm the target is healthy before you flip the VSchema.
Other constraints: schema changes during an active job should go through Vitess online DDL so source and target stay in sync. Not every MySQL data type replicates cleanly through vreplication; validate your types in staging. Behavior and command names change between Vitess releases, so check the operations guide for your exact version before running anything.
Closing checklist
- Run a trial reshard of a small table on staging.
- Confirm vreplication lag is near zero and error rows are absent.
- Schedule cutover during low traffic with a write-drain plan.
- Review your Vitess version's release notes for command changes.
If the staging trial passes, you have a repeatable path to move tables between shards without stopping the application.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.