When moving an old Spring legacy project to Spring Boot and Docker, the scariest moment is always flipping the switch in production.
No matter how much you test on local or staging, it is hard to reproduce every weird request parameter and edge case from real users.

If data silently gets corrupted or lost after launch, fixing it later takes way more effort.
So during the migration, I put two safety nets in place before cutting over.

1. Sending live traffic copies with Nginx mirror

The first thing I used was Nginx’s mirror feature.
The live legacy server still handles real user requests and sends responses back, while Nginx quietly copies each request and sends it to the new Spring Boot server in the background.

location /api/ {
    proxy_pass http://legacy_backend;
    mirror /mirror;
    mirror_request_body on;
}

location = /mirror {
    internal;
    proxy_pass http://new_boot_backend$request_uri;
}

The response from the new server is ignored and never reaches users, so production stays completely safe.
Leaving this on for a few days and watching the new server’s logs quickly caught things we missed in staging, like NullPointerExceptions, JSON parsing errors, and missing query parameters.

There is one thing to be careful about when using it.
If you mirror write requests like POST directly to a server connected to the live DB, you can end up with duplicate rows or double external API calls.
So it is safer to start with GET endpoints first, or point the new server to a separate test DB just to catch errors.

2. Cross-checking old and new DB data with Spring Batch

Once the traffic looked clean, the next step was data parity.
After migrating data from the old DB to the new DB, matching row counts isn’t enough. You want to be sure the actual column values match too.

Since you can’t check millions of rows by hand, I wrote a simple Spring Batch job to compare them in chunks.

@Bean
public Step compareOrdersStep(JobRepository jobRepository,
                              PlatformTransactionManager txManager) {
    return new StepBuilder("compareOrdersStep", jobRepository)
            .<OrderRow, OrderDiff>chunk(1000, txManager)
            .reader(legacyOrderReader())
            .processor(orderDiffProcessor()) // compare key columns with new DB
            .writer(diffLogWriter())         // log only mismatched rows
            .build();
}

On the first run, almost every row showed up as a mismatch, which surprised me.
It turned out to be tiny millisecond differences in updated_at timestamps and null vs empty string handling.
Once I excluded those meta columns and focused on core business columns like amounts, statuses, and foreign keys, the job caught several missing or wrongly mapped rows before we went live.


Looking back, setting up these checks before switching over did more to save our launch night than anything else.
Even without full test coverage, combining live traffic mirroring and batch DB comparison gives you a lot of confidence when swapping out a legacy server.