Smooth System Migration: Practical Methods to Avoid Destructive Upgrades
This article explains how to migrate systems without a one-time cutover. It covers the risks of destructive upgrades, dual-running and compatibility periods, data synchronization design, staged canary releases, and prerequisites for retiring the old system. Readers will learn practical checkpoints and metrics for deciding when to move to the next migration stage.
In system refactoring or technology stack migration, one of the most common mistakes is to push the new system online all at once and then shut down the old service directly. This approach is often called a “destructive upgrade.” Its cost includes not only technical failures but also interrupted user workflows, data inconsistency, and declining trust. This article follows the actual sequence of a migration and explains what to do at each stage and which metrics determine whether the team can move to the next stage.
1. Typical Risks of Destructive Upgrades
- Business path interruption: Users are already accustomed to the old APIs and old pages. If the old APIs are taken offline abruptly, in-flight requests fail, and users may submit orders repeatedly or lose unsaved data.
- Data inconsistency: The old and new databases have different structures. Without a synchronization mechanism, data written to the old database cannot be found in the new database, and reports and reconciliation will be wrong.
- No rollback path: After the old system is deleted, if the new system exposes defects during peak hours, the team can only fix and endure at the same time, and recovery time depends entirely on how fast the fix is.
To judge whether a migration is safe, the key is to check two things: whether the old system can still take over traffic at any time, and whether data on both sides can be cross-checked.
2. Dual Running and Compatibility Period
At the beginning of the migration, the old system and the new system should be online at the same time. The gateway or routing layer distributes requests to both sides. The old APIs keep their original request format and response structure, while the new APIs are developed according to the new specification. The new APIs must cover all business rules of the old APIs and pass the same regression test suite.
Dual running cannot continue indefinitely. Maintaining two sets of APIs for a long time increases testing costs and makes data issues harder to troubleshoot. The migration plan should specify the following three things:
- The compatibility deadline for the old APIs, with notice to callers at least two release cycles in advance.
- Exit criteria: new API calls reach 100% of traffic, and there are no new old-API calls for 14 consecutive days, or only a small number of registered internal callers remain.
- How to retain the old APIs after retirement: return an explicit deprecation notice and keep read-only access for a period of time to support historical data queries.
3. Data Synchronization Design
Data is the hardest part of a migration to roll back. Prefer the approach where “the old database is the source of truth and the new database is synchronized in one direction.” The old database remains the only write point, and data is synchronized to the new database through a change log such as binlog or through event messages. This approach does not create circular synchronization and does not require resolving conflicts from simultaneous writes on both sides.
If the business requires bidirectional writes, the following issues must also be handled:
- Circular synchronization protection: Each record carries a source identifier, and the synchronization program skips changes that it wrote itself.
- Idempotent writes: Use the business primary key plus version number as the idempotency key so that duplicate messages do not create duplicate data.
- Conflict resolution: Define which side takes precedence, or merge by version number, and record conflict logs.
- Scheduled reconciliation: Compare record counts and checksums on both sides daily by primary key and key fields, and trigger an alert when the difference exceeds a threshold.
The following code shows compensation logic on the write side in one-way synchronization.
public void writeData(DataEntity entity) {// The old database is the source of truth; first ensure current business succeedsoldDbMapper.insert(entity);try {// The event carries business key and version for idempotent writes on the consumer sideeventBus.publish(new DataSyncEvent(entity.getBizId(), entity.getVersion(), entity));} catch (Exception e) {// On publish failure, store in local compensation table for scheduled retrysyncRetryMapper.insertPending(entity.getBizId(), entity.getVersion());log.warn("sync event publish failed, bizId={}", entity.getBizId(), e);}}
After the consumer reaches the retry limit (for example, 5 times), the message enters a dead-letter queue. Operations staff repair data based on the dead-letter content and rerun the reconciliation task. The goal of compensation is to make the new database eventually consistent with the old database, not to guarantee zero synchronization latency.
4. Staged Canary Releases
Canary releases should be rolled out in stages. Each stage must define entry criteria and rollback criteria.
Stage 1: Internal whitelist. Select internal test accounts and a small number of voluntary users. Selection criteria include moderate account activity, coverage of major business types, and exclusion of large customers or critical billing accounts. Exit criteria are that the success rate of core paths (login, ordering, payment, or similar main flows) is comparable to the old system, and there are no blocking defects.
Stage 2: Stable user bucketing with gradual traffic increase. Increase traffic in steps of 1%, 5%, 20%, 50%, and 100%. Observe each ratio for at least one full business cycle, usually one day; if there is a periodic peak, cover one peak. Bucketing must be stable: the same user should always hit the same side throughout the canary period. Otherwise, users will switch back and forth between old and new pages, and data reads and writes will be misaligned.
The following is an Nginx example. split_clients hashes the key value, so the same user ID gets the same result every time.
upstream old_backend {server 10.0.0.11:8080;server 10.0.0.12:8080;}upstream new_backend {server 10.0.1.11:8080;server 10.0.1.12:8080;}# About 5% of users go to the new system; the rest stay on the old systemsplit_clients "${http_x_user_id}" $service_pool {5% new_backend;* old_backend;}server {location /api/service {proxy_pass http://$service_pool;}}
If a request does not carry a user ID, all anonymous requests have the same hash result, and the entire batch lands on the same side. Therefore, the gateway should first add an identifier for such requests, or route them to the old system by default.
5. Prerequisites for Retiring the Old System
All of the following conditions must be met before retirement; none can be omitted. The thresholds in the table are examples and should be adjusted based on pre-migration baseline data.
| Check | Example threshold | Description |
|---|---|---|
| 5xx error rate | No higher than the old system baseline plus 0.1 percentage point | Measured separately by API |
