Legacy modernization, part 5: Hand over writes for order creation and cancellation
In this fictional shop, a customer clicks the order button. The server saves the order, but the response is lost. If routing switches before the customer retries, the new system may accept the same request and create a second order. The first decision for cutover is which system handles the same creation request and writes to the same order ID through to completion.
1. Pin the retry path before creating the order
The order ID is available only after creation. Until then, use the customer and request key to decide which path takes the first request. In a record both paths can consult, associate the request key, processing path, processing state, and order ID. Treat reuse of the same key with a different cart or amount as an input conflict.
Order creation may commit successfully even if the connection drops before the server reports acceptance. Store the request key in the order creation transaction as well, so the retry can find the existing order. Expanding the group of accounts sent to the new path leaves already accepted requests on their assigned path.
2. Route cancellations and administrative changes to the order owner
When the new module starts taking some new orders, send later cancellations, payment callbacks, and administrative changes to the owner of each order. For existing orders, choose a scope and check writes and asynchronous work in progress before handing it over. Stop the old workers before the handover and confirm that writes already started have finished. Check current ownership at the write boundary so even a worker that wakes up late cannot make changes.
If shipment confirmation and a cancellation request race, use the state of that order to decide which transition succeeds. Use locking or a version check when updating the state. Record orders with outstanding refunds or stock releases as cancellation in progress. Mark cancellation complete once the required operations have been accounted for. Give each external operation its own operation ID. If the payment provider’s response is lost, reconcile the original request or the refund transaction. Before reusing a provider idempotency key, check its scope and validity period. Example idempotency contract from Stripe
Write cutover runbook
| Timing or signal | Action |
|---|---|
| Before cutover | The order owner rehearses retries after a lost response, the shipment and cancellation race, partial refunds, and late payment callbacks. The deployment owner checks that old workers cannot write and that late requests reach the current owner. |
| Both paths are seen writing the same order | Stop expanding the scope and pause new writes within it. Identify in-flight work, reconcile the data change history and external effects, and establish a single write owner. |
| Failure before the new path commits | Check that the new path has no committed writes and has initiated no external requests. If both conditions hold, return to the old path. |
| Failure after the new path commits | Temporarily restrict intake and preserve newly committed orders, cancellations, and external operations. Transfer ownership back only if you can demonstrate compatibility with the old version and that changes can be applied back to it. Otherwise, fix the issue at the new source of truth and resume from there. |
The cutover ends later than the first successful arrival of new orders. Process cancellations of orders placed before cutover and late payment callbacks, then check whether any business operations still depend on the old path.
Previous — Legacy modernization, part 4: Run order reports in parallel before switching over
Next — Legacy modernization, part 6: Safely retire the old order system
Discussion