Scrivio Interview library
ScenarioIntermediate7 min read · updated 12 November 2026

You must split 8 shards into 16 for a MySQL-based system without downtime. Describe the process step by step.

We prepare 8 new target shards and a new mapping, ideally moving logical buckets (for example 1,024 buckets over 8 shards, 128 each, of which 64 per shard move) rather than rehashing keys. For each moving bucket we copy a consistent snapshot and then stream binlog changes, with Vitess VReplication or a CDC tool, until the target is caught up, verify with row counts and checksums, and cut over bucket by bucket: block writes for those keys for a moment, confirm the stream has caught up, switch routing and resume. Old copies stay read-only until we are confident, and the whole process is rehearsed in staging first.

Why this question is asked

Splitting shards without downtime is one of the hardest routine operations in a sharded system: the data is live, writes keep arriving, and any mistake loses or duplicates customer data. Interviewers ask for the steps because they show whether we understand the mechanics of an online move, copying, catching up, verifying and switching, and the order in which they must happen. In this answer, we will set up the mapping, go through the copy and catch-up, verify, perform the cut-over, and clean up, with the reasoning for each step.

1Prepare the Targets and the New Mapping

We start by provisioning 8 new MySQL shards with the same schema, replication setup and monitoring as the existing ones. Then we decide what moves. If the system already uses logical buckets, for example bucket = hash(key) % 1024 with 128 buckets per shard, then going to 16 shards means each old shard keeps 64 of its buckets and hands 64 to one new shard. No key changes bucket, so nothing is rehashed; we move whole buckets.

If the system routes keys directly with hash % 8, the first step is to introduce buckets anyway. Going from hash % 8 to hash % 16 happens to be friendly, because a key on shard s either stays on s or moves to s + 8, but defining buckets now makes this and every future split a matter of moving buckets. The new mapping is written as data, in a table or configuration that the routing layer reads, not as a code change.

Mapping before and after the split (1,024 buckets)
BucketsBefore (8 shards)After (16 shards)
0 - 63shard 0shard 0 (stays)
64 - 127shard 0shard 8 (moves)
128 - 191shard 1shard 1 (stays)
192 - 255shard 1shard 9 (moves)
......same pattern for shards 2 to 7
Half of each old shard's buckets move to one new shard; no key is rehashed.

2Copy the Data and Stream the Changes

For each moving bucket we need a full copy on the target that then stays current while writes continue on the source. The standard way is a snapshot plus change streaming. We take a consistent snapshot of the rows in the moving buckets and record the binlog position (or GTID set) at which the snapshot was taken. Then we read the binlog from that position and apply every insert, update and delete for those buckets to the target.

With Vitess this is exactly what VReplication does, driven by a Reshard workflow. Outside Vitess, a CDC tool such as Debezium, gh-ost-style binlog readers, or a custom binlog consumer can do the same job. The copy runs throttled, so the source shard's latency and the replicas' lag stay within limits, and it can take hours or days for large shards. That is fine, because nothing has switched yet; the old shards still serve all traffic.

Notice why the binlog position matters. Rows change while the snapshot is being taken; by starting the stream exactly where the snapshot ends, every change is applied either by the snapshot or by the stream, never neither. Applying the stream must be idempotent too, since a restart may replay some events.

3Verify Before Switching

When the stream has caught up, so the target is only seconds behind, we verify. Per bucket, we compare row counts between source and target, and we compare checksums, for example a hash over the primary key and the updated_at column of every row, computed in chunks on both sides. Vitess provides VDiff for this. Differences must be explained and fixed before cut-over; a bucket that does not verify does not move. Running verification while writes continue produces small transient differences, so we either verify against a paused stream at a consistent point or rerun the check until it is clean.

SQL
-- Per-bucket check, run on source and target
SELECT bucket_id, COUNT(*) AS rows_n,
BIT_XOR(CRC32(CONCAT_WS('#', id, updated_at))) AS checksum
FROM orders
WHERE bucket_id BETWEEN 64 AND 127
GROUP BY bucket_id;
-- source: 64 | 1,203,442 | 3920114771
-- target: 64 | 1,203,442 | 3920114771 match: bucket 64 can move

4Cut Over Bucket by Bucket

The cut-over is the moment of truth and has a strict order. First, block writes for the keys in the buckets being switched, for a few seconds: the routing layer returns a retryable error or holds the requests briefly. Second, wait until the stream has applied everything up to the current binlog position, so the target is exactly equal to the source. Third, switch routing for those buckets to the new shard. Fourth, resume writes, which now go to the new shard.

Notice why writes must stop, even briefly. If writes continued during the switch, some might land on the source after the last change was streamed, and they would be lost on the target. Blocking for a moment makes the switch exact. Doing it per bucket, or per small group of buckets, keeps each pause short and limits the blast radius: if a problem appears after switching ten buckets, the other 502 have not moved. In Vitess, SwitchTraffic performs this sequence, usually switching reads first and then writes. Reads can be switched first because a slightly stale read on the target is harmless, while the write switch must be exact.

Step throughCut-over for one group of buckets
  1. Block writes for these bucketsrouting returns retryable errors, a few seconds
  2. Stream fully caught up?
    YesSwitch routing to the new shardNoWait; abort if over the time limit
  3. Resume writesnow served by the new shard
  4. Stop or reverse the streamold copy kept read-only for rollback

4 steps in order. Play them, or step through them one at a time.

The write pause lasts seconds and affects only the keys in the moving buckets.

5Keep the Old Copies, Then Clean Up

After the switch, the old copies of the moved buckets stay in place, read-only, for a while, for example a week. Some tools can also reverse the replication direction so the old copy keeps receiving changes from the new shard, which makes rolling back a matter of switching routing again. Once metrics, error rates and a final verification look good, we delete the moved rows from the old shards in throttled batches, so we do not cause the replication lag and bloat we were trying to avoid. Finally, the whole procedure should have been rehearsed in staging on a production-sized copy, including a deliberate rollback, so that the timings and the scripts are known before the real run.

6Follow-up questions

Why are logical buckets better than mapping keys directly to physical shards?

Because they separate the key's identity from its location. A key maps to a bucket by a formula that never changes, and buckets map to shards through a small table. Resharding then moves whole buckets and edits the table, with no rehashing; each bucket can be copied, verified, switched and rolled back on its own; and we can add one shard at a time instead of doubling. With direct mapping, changing the shard count changes the formula for every key at once.

What happens to cross-shard transactions or joins during the split?

If the data model keeps each key's related rows in the same bucket, for example all orders of a customer share the customer's bucket, they move together and nothing changes for the application. Data that spans buckets is the reason designs keep related rows under the same shard key.

How long should the write pause be?

Usually a few seconds per bucket group. We set a hard limit, for example 10 seconds; if the stream does not catch up in time, we abort the cut-over, resume writes on the source and try again later.

7Conclusion

In this answer, we split 8 MySQL shards into 16 without downtime. We prepared the targets and a new mapping of logical buckets, copied each moving bucket with a snapshot plus binlog streaming such as Vitess VReplication, verified with per-bucket row counts and checksums, and cut over bucket by bucket with a short write block, a caught-up stream and a routing switch. Old copies stayed read-only for rollback before throttled cleanup, and the whole procedure was rehearsed in staging first.

What to say in the interviewAbout 90 seconds aloud

Open with

First I would prepare the 8 new shards and a new mapping. Ideally the system already has logical buckets, say 1,024 buckets with 128 per shard, so each old shard keeps 64 buckets and hands 64 to a new shard, and no key is rehashed.

Then, if they want more

If it routes with hash mod 8 directly, I would introduce buckets as part of this work. Second, for each moving bucket I copy a consistent snapshot and record the binlog position, then stream binlog changes from that position to the target until it is caught up. With Vitess that is the Reshard workflow using VReplication; otherwise a CDC tool.

The copy is throttled so the source and its replicas stay healthy. Third, I verify per bucket with row counts and chunked checksums, or VDiff in Vitess, and nothing moves until it matches.

Fourth, I cut over bucket by bucket: block writes for those keys for a few seconds, wait until the stream has applied everything, switch the routing for those buckets, and resume writes. Reads can switch first. I set a time limit and abort if catch-up takes too long.

Fifth, I keep the old copies read-only, ideally with reverse replication, so rollback is just a routing switch, and only after a week or so delete the moved rows in throttled batches. All of this is rehearsed in staging on production-sized data, including a rollback.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "You must split 8 shards into 16 for a MySQL-based system without downtime. Describe the...": https://scrivio-interview-library.netlify.app/databases/partitioning-and-sharding/5b19c16749/