Legacy modernization, part 4: Run order reports in parallel before switching over
An order paid on November 30 for KRW 50,000 received a partial refund of KRW 10,000 on December 1. A report grouped by payment date shows KRW 50,000 in November payments. A report grouped by refund date shows KRW 10,000 in December refunds. The cumulative net payment for the order is KRW 40,000. All three figures come from the same order and answer different questions.
Before moving to the new aggregation, define what counts on which day and compare the same set of transactions in both reports. In this fictional shop, start with one operational report that totals confirmed payments and refunds.
1. Record the accounting rules in documentation and tests
Use the payment confirmation timestamp for payments and the refund confirmation timestamp for refunds. Define the business-day boundary and the closing rules. This example uses midnight Korea time. For transactions that arrive after closing, either recompute the affected period or record an adjustment according to the policy set by the person responsible.
An order can have two partial refunds. Deduplicating refunds by order ID would drop the legitimate second refund. Use event IDs to detect duplicate deliveries and source transaction keys such as payment transaction IDs or refund IDs for aggregation. If the same key arrives with a different amount, check whether it represents a correction or a data conflict before overwriting anything.
2. Align the boundary between historical data and new changes
Orders keep coming in while historical transactions are copied. Define both the point in time represented by the historical data and the corresponding starting position for the change stream. PostgreSQL logical decoding lets you read the initial state from the snapshot exported when a replication slot is created, then receive subsequent changes. If you use application events, define separately how to guarantee the same boundary. Copying data with a cutoff based solely on created_at can miss late commits or updates to existing transactions. PostgreSQL logical decoding and exported snapshots
- Load a consistent snapshot into a separate reporting store and record the corresponding position in the change stream.
- Apply changes from that position onward. Where possible, apply the transaction and save the processing position in the same database transaction. A message redelivered after commit must never count the same transaction twice.
- Align the reporting cutoff and the set of included transactions in both reports. Compare counts and amounts by period, transaction type, and currency. For groups with discrepancies, reconcile down to individual transaction IDs.
Report cutover runbook
| Situation | Action and verification |
|---|---|
| Before releasing the new report | The reporting owner checks payments, partial refunds, month boundaries, and late arrivals. Operators must be able to see the point through which source data has been incorporated. |
| Counts match but amounts differ | Hold the release. Compare currencies, individual refund records, and amounts per transaction. Even when monthly totals match, check whether differences in two separate transactions canceled each other out. |
| Updates are delayed or missing after release | Route queries back to the old report if it meets the validation criteria. Otherwise, display the last verified point. Recompute the affected period in a separate space, validate it, and then replace the affected data. |
A matching monthly total is only one cutover check. Operators must be able to explain which transactions make up a figure and recompute only the periods that need it. With reads, notifications, and reporting checked separately, the next part hands over responsibility for changing order state.
Previous — Modernizing a legacy monolith, part 3: Move order notifications without sending duplicates
Next — Legacy modernization, part 5: Hand over writes for order creation and cancellation
Discussion