Skip to content

Expert Answers to Your Magento, Shopify & Shopware Questions

Vendor-neutral, engineer-written explanations. Clear definitions first, then practical steps with real examples — no fluff.

Stagebit builds and maintains stores on Magento, Adobe Commerce, Shopify, Shopware, and Laravel, and this library holds the questions our own engineers get asked most often on each platform.

How do I reconcile two systems that have drifted out of sync?

SB
Written by Stagebit Engineering Team
Updated November 2026 7 min read Verified by engineers

To reconcile two systems that have drifted out of sync in Laravel, find every place they differ, decide which system is correct for each field, and correct the wrong side in controlled batches. Never copy one system over the other wholesale. In practice, an Artisan command builds the diff and queued jobs apply the approved fixes.

Quick answer

Reconciliation takes seven steps. Set a source-of-truth rule per field, match records on a shared key, diff both sides into missing, orphaned and conflicting records, review the dry-run report, apply idempotent (safe to run twice) fixes in batches, verify each result, then schedule the same diff in report-only mode. Drift then shows up as a short report you can read in minutes. Fix the cause too, usually a failed job, a dropped webhook or a manual edit on the wrong side.

Why two systems drift out of sync

Data drift between two systems is most common when a Laravel application exchanges data with an ERP (enterprise resource planning), PIM (product information management), WMS (warehouse management) or CRM (customer relationship management) system. Drift almost always traces back to a short list of causes. Knowing which one you have decides how you fix it.

  • A sync job exhausted its retries and nobody checked the failed jobs table.
  • A webhook never arrived, arrived twice, or arrived out of order.
  • Someone edited a record directly in the other system and bypassed the integration.
  • A mapping or format change, such as timezone, rounding, units or status codes, altered how values reach one side.
  • A bulk import or migration touched one system only.

What to check before you change any data

  • Take a snapshot or backup of both sides first, so every change can be rolled back.
  • Run the first batch on a small set of records and compare the result by hand before scaling up.
  • Pause the live sync job while you reconcile, or new writes will race your fixes.
  • Treat orphaned records as items to review. Never delete them automatically.
  • Check the transaction history before you overwrite a completed order or a financial record.

How to reconcile systems that are out of sync, step by step

Flowchart of how to reconcile out-of-sync systems: diff, review, apply fixes, verify, then re-run the diff on a schedule.

Step 1: Decide which system owns each field

A diff only shows what differs. It cannot tell you which side is right, so ownership comes first. Ownership works at two levels.

  • Record-level ownership decides which system controls whether a record exists and how its lifecycle runs, including creation, archiving and deletion.
  • Field-level ownership decides which system is authoritative for each individual field. The source of truth for a field is the system whose value wins when the two disagree.

The two levels can differ. A system can create a record without owning every field in it. For example, a webshop may create an order while the ERP owns its invoice and fulfilment status. Assign one owner per field. A typical split gives the ERP price and financial data, the PIM product descriptions and images, and the WMS warehouse stock. Your own architecture decides the real split.

The table shows why this matters. The values are illustrative.

Field (SKU PROD-1001)LaravelERPOwnerFix
NameOffice ChairOffice ChairNone neededNo action
Price100120ERPUpdate Laravel to 120
Stock2518WMSCheck the WMS before changing either side

The ERP disagrees with Laravel on stock, but the ERP does not own stock. Copying its number would overwrite the right value with the wrong one. Even the WMS total deserves care. If the WMS tracks stock movements and reservations, reconcile those movements, because copying a total hides what happened.

Last-write-wins by timestamp is tempting. It breaks when the two clocks disagree, or when one system re-saves unchanged records and stamps them as new. Field ownership takes longer to agree on, but it gives the same answer on every run. An outdated value is simply a conflict that the ownership rule settles.

Step 2: Match records on a shared key

Store the other system’s identifier on your side, such as a SKU, order number or external_id, in its own column with a unique index. Prefer identifiers that never change. Names and email addresses change over time and are often not unique, so use them only as a fallback and review those matches by hand.

Normalise each field by its own rules before you compare. Trim stray whitespace, but check whether a system treats letter case as significant before you lowercase an identifier. Normalise timestamps, which mark a real moment in time, to UTC. Keep date-only values, such as birthdays or accounting dates, as dates in one consistent format, because a timezone conversion can shift them by a day.

Step 3: Build a read-only diff

Write an Artisan command that reads both datasets and compares them without changing anything. Stream local records with lazyById() or chunkById() to keep memory flat. Read every page of the remote API within its rate limits, or the diff will report records beyond the first page as missing. Compare a hash of only the fields you care about.

Sort every difference into one of three groups. Here the owning system is the one that controls the record’s existence and lifecycle:

  • Missing: the record exists in the owning system but not in the other.
  • Orphaned: the record exists in the other system but the owning system no longer has it.
  • Conflicting: the record exists in both with different values.

Before you call a record missing or orphaned, check whether someone deleted it on purpose. Look at deletion history, archived records, soft deletes and deletion markers (tombstones). If a Laravel model uses soft deletes, Eloquent leaves its deleted rows out of normal queries, so include them with withTrashed() when you diff.

Write the results to a reconciliation table with columns for record type, local ID, external ID, field name, both values, status, resolved time and error message. Keep credentials and unnecessary personal data out of it.

For large datasets, save the last processed key as a checkpoint so an interrupted run resumes where it stopped. Default the command to dry-run mode and require an explicit --apply flag.

Step 4: Review the diff before you write anything

Read the counts first. If a large share of records conflict on the same field, you probably have a mapping or format bug, not drift. Fix the mapping before you touch any data. Then sample a few rows from each group and check them by hand against both live systems.

Step 5: Apply fixes with idempotent jobs

Dispatch the approved fixes as queued jobs, one job per small chunk of keys, inside a Bus::batch. The batch lets you track progress and handle failures in one place. Inside each job, write records in your own database with Laravel’s upsert(), keyed on the external identifier, so running the same fix twice produces the same result. Laravel’s upsert() only touches your local database. It does not update the ERP, PIM, WMS or CRM.

All databases except SQL Server require the key columns to have a primary or unique index. That is the index from Step 2. MySQL and MariaDB ignore the second argument of upsert() and use the table’s real primary and unique indexes to find an existing row, so create the index first. Still pass the key columns as the second argument, because Laravel 13 throws an exception if it is empty.

Have each job re-read the record in both systems just before it writes, and skip the fix if the difference has already gone. The data can change between the diff and the apply.

Do not rely on ShouldBeUnique for safety here. According to Laravel’s queue documentation, unique job constraints do not apply to jobs inside batches. Use the WithoutOverlapping middleware keyed on the record identifier to stop two jobs from touching the same record at once. Raise the job’s tries value as well, because a released job still uses up an attempt.

For writes to an external system, use its API’s upsert, update-by-reference or idempotency-key support if it has one. If it does not, check whether the record already exists before you create it. Log every change with the old value, new value, source and run ID. The log adds write overhead, and it is what makes a rollback possible.

Making a sync safe to re-run is a topic of its own. See how to make a sync process safe to re-run for the full pattern.

Step 6: Verify each fix and re-run the diff

A successful API call does not prove the systems now match. The destination can reject an update, apply it partially or return an unexpected response. For each fix, check the response, store the external reference or version, and mark the difference resolved only after the destination confirms it. Fetch the record again where the response is not enough.

When the batch finishes, run the diff again. The target is zero unresolved, unexpected differences. Do not count approved transformations, expected sync delays, rounding rules or differences you chose to keep. Anything unexpected that remains goes to a manual review queue for a person to decide.

Step 7: Schedule the check in report-only mode

Register the command in routes/console.php without the --apply flag, so the scheduled run only reports:

use Illuminate\Support\Facades\Schedule;

Schedule::command('sync:reconcile')
    ->dailyAt('02:00')
    ->withoutOverlapping()
    ->onOneServer();

Pick the frequency from how fast the data changes. Stock and order feeds may need an hourly check, while a slow-moving catalogue may need only a nightly one. The onOneServer() method stops several application servers from running the same task. It needs the database, memcached, dynamodb or redis cache driver, with all servers sharing one cache.

How to stop the systems drifting again

Reconciliation clears the backlog. These habits keep the cause from coming back.

  • Alert on new rows in the failed_jobs table and on any batch that finishes with failures. Laravel can retry the failed jobs of a batch with queue:retry-batch.
  • Add a backoff to sync jobs so a transient API error triggers a delayed retry.
  • Deduplicate webhooks by the event ID the sender provides, and verify each signature.
  • Restrict direct edits in the other system for fields that Laravel owns, where its permissions allow.

Where to start

Start with the dry run. Even if you never apply a single fix, the diff report shows how large the drift is and where it begins. That tells you whether you need a one-off clean-up or a change to the integration itself. If your integration between Laravel and an ERP, PIM, WMS or CRM keeps drifting, you can talk to our Laravel development team about it.

Was this answer helpful?

Your feedback helps us improve our answers.

Still need help?

Questions about Laravel integrations that keep drifting?

If your Laravel application and an ERP, PIM or WMS keep falling out of sync, we're happy to walk through where the drift starts and how to close it.

Talk to Laravel Experts