← Writing

Modernizing a legacy monolith, part 1: Move the order list first

On this page

If adding a shipping status to the order list forces you to retest payments and inventory, consider starting the migration with the order list query. Build a read module inside the same application and keep the URL and response format the existing screen uses. Compare the new module’s results with the old ones before moving a subset of users. If problems surface, route those reads back to the old module.

The example is a small online store that handles order intake, payments, inventory, and reads in one application. This change covers the order list in the admin interface. Order creation and modification continue through the existing paths. Start by routing requests within the same application. If the read module eventually needs its own deployment, a façade can then direct requests for that feature to the new system. Strangler Fig pattern in the Microsoft Azure Architecture Center

Moving order-list reads first lets you verify and roll back the new path while leaving order writes in place. The series covers six steps: reads → order events → notifications → statistics → order creation and cancellation → legacy retirement. The next part adds a publication record to the existing order transaction and checks that the records make it through before connecting notifications and statistics.

1. Document the behavior operators rely on

Watching how operators find an order is a better starting point than reading function names in the old code. Open the order list with two admin accounts. Try the filters they use most and move between pages. Turn the results into a contract the new module must meet.

Behavior to check Test case to keep
Who can see which orders? When a store A account searches for a store B order, that order is absent from the results.
What do date and status filters mean? Orders on date boundaries and cancelled or partially cancelled orders are included or excluded according to the existing business rules.
How is the list sorted? Two orders with the same timestamp retain their relative order after a refresh or page change.
What happens when a request has no matching result or is invalid? The screen gets the response it expects for an empty first page and for invalid search criteria, respectively.

If existing behavior looks odd, ask the person responsible who depends on it. Replace the read module and change business rules in separate PRs so you can trace any difference to the change that caused it.

2. Build the new read path within the same deployment

Add the new module behind the existing screen’s entry point. While the rollout flag is off, everyone gets results from the old module. The new module uses the same authorization rules and initially reads the existing order database. Check the code and execution records to confirm that the path never changes state, creates an export job, or sends notifications. By moving reads alone, you can defer copying data to a new database or handing off order writes.

Start by sending identical inputs to both modules with approved test data. Compare order IDs and order, statuses, totals, and error responses. When mirroring production requests for comparison, cap the sample and concurrency. Reading twice can increase database load. If an order changes between queries, an ordinary update can look like a mismatch. Compare from the same data snapshot where possible and record cases you need to recheck because the snapshots could not be aligned.

Authorize the request and select the new or old module using the flag and account group. Both modules read the existing order database and return the existing response format.

Authorize the request and select the new or old module using the flag and account group. Both modules read the existing order database and return the existing response format.

The pseudocode shows how one list request is routed. It omits mirrored comparison requests.

authorize(request.account)
if rollout.enabled and rollout.includes(request.account):
    module = newOrderReadModule
else:
    module = legacyOrderReadModule
return module.list(request, existingOrderDB).asExistingResponse()

3. Assign accounts to stable rollout groups

Route internal operations accounts to the new path first. Pin each account to its path so it stays there after refresh. This keeps pages from mixing versions and makes it possible to trace requests from accounts that hit problems.

Compare error rate, response time, and database load for the two paths over the same period. Check what users actually experience too, including missing cancelled orders or exposure of orders from another store. Agree on acceptable limits and the observation window before expanding. Include routinely busy order periods and common tasks in the sample. Evaluating a small group before deciding whether to expand is called a canary rollout. Canarying Releases in the Google SRE Workbook

Cutover runbook

Step Owner Action and verification
Prepare Release owner Record the release version, target accounts, flag location, and dashboard links. Verify in a pre-production environment that turning off the flag sends new requests to the old module.
Start On-call engineer Switch internal accounts and record the start time. Check normal reads, denied access, date boundaries, and pagination.
Expand On-call engineer and business owner Expand to the next group when error rate, response time, database load, and result comparisons meet the agreed criteria throughout the observation window. Hold at the current scope if the sample is too small or the cause of a difference remains unclear.
Halt On-call engineer Stop expansion if orders from another store are exposed, orders required by the business go missing, or errors, latency, or load exceed the agreed limits.
Roll back Release owner Turn off the flag. Confirm that refresh and pagination use the old path for previously switched accounts. If load caused the problem, disable comparison reads as well.
Verify recovery On-call engineer and business owner Confirm that requests to the new path have stopped and that key reads and metrics have recovered. If orders were exposed, start incident response to determine the affected scope.

Rerouting reads is sufficient for recovery here because order writes and the database schema stay the same, and the new read path does not trigger external work. If a later cutover changes these conditions, first decide how to preserve writes the new system has accepted and reconcile effects already delivered externally.

After the cutover, check whether batch jobs, exports, or older clients call the same query directly before removing the old path. Once the owners check remaining dependencies and recovery materials, remove the old path and rollout flag. The new order read module can then serve as a reference for migrating the next function.

Next — Legacy modernization, part 2: Add an outbox to the order transaction

Discussion

View on GitHub ↗