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 handle failed sync jobs in Laravel so nothing is silently dropped?

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

Handling Laravel sync failures means closing two gaps. Every failure path in your jobs must end in a visible failed state, and you need a separate check for syncs that never reached the queue. Laravel failed jobs cover only part of the problem.

The Laravel 13 queue documentation says an asynchronous job lands in failed_jobs after it exhausts its attempts. It also says failed synchronous jobs are not stored there.

As a result, a sync that Laravel deletes, your code swallows, or nothing ever dispatches leaves no row at all. This page assumes your sync is a queued job that pushes data between a Laravel app and another system, such as an ERP or a storefront.

Quick answer

To stop Laravel sync failures going unnoticed, run each sync as its own queued job with finite Tries and Backoff. Never swallow exceptions in handle(), record terminal failures in failed(), and alert from a Queue::failing listener. Then monitor queue depth and add scheduled reconciliation, because failed_jobs cannot see a sync that was deleted or never queued.

Where does a Laravel sync get dropped without a trace?

Before adding any tooling, find the paths where a Laravel job fails silently or disappears. The diagram shows where each one sits in the pipeline, and the table maps every point to the step that covers it.

Flow of a Laravel sync from saved record to queue, worker and failed_jobs, with the points where a sync can vanish marked
PointHow the sync disappearsWhat covers it
AThe sync was never queued, for example because the process died after saving the record but before dispatching.Step 8.
AA synchronous dispatch, because failed synchronous jobs never reach failed_jobs.Step 1. Queue the job so a failure reaches failed_jobs.
BA queue worker has stopped or fallen behind, so jobs wait without ever failing.Step 7.
CLaravel removes the job without recording a failure, through the missing-models option, the Skip middleware, dontRelease() on overlap or rate-limit middleware, or deleteWhen() on exception throttling.Step 8. Avoid these options on sync jobs, or log whenever one triggers.
DA try/catch block inside handle() logs the error and returns, which tells Laravel the job succeeded.Step 3.
EThe failed-job store is disabled, or pruned on a schedule with no alert attached.Steps 5 and 6.

How do you handle Laravel sync failures step by step?

1. Dispatch the sync after the transaction commits

First, queue the sync as its own job. The afterCommit() method holds the dispatch until the open database transaction commits, so a worker never picks up a record that is not saved yet.

SyncOrder::dispatch($order->id)->afterCommit();

2. Set finite retries and separate transient errors from permanent ones

Laravel attempts a job once by default. For example, one API timeout sends the sync straight to failed_jobs.

Set Tries and a Backoff array on the job class so transient errors retry with growing delays. A value on the job takes precedence over the worker’s --tries flag.

use Illuminate\Queue\Attributes\Backoff;
use Illuminate\Queue\Attributes\Tries;

#[Tries(5)]
#[Backoff([60, 300, 900])]
class SyncOrder implements ShouldQueue
{
    // ...
}

The 13.x documentation shows these as attributes. On Laravel 12 and earlier, declare public $tries = 5; and public $backoff = [60, 300, 900]; instead. Choose the delays from the destination API’s rate limits and expected recovery time.

If the job uses WithoutOverlapping or RateLimited middleware, raise Tries as well. Every release back to the queue consumes an attempt, so the default of one attempt sends an overlapping job straight to failure.

Attach the FailOnException middleware for errors that retrying cannot fix, such as a revoked permission, a deleted record, or a validation rejection from the destination system. Those jobs should fail immediately and visibly, which saves the remaining attempts.

3. Record every attempt and never swallow exceptions

Keep a sync record per order with status, attempts, last_error, last_attempt_at, and synced_at columns. Load the order with findOrFail() so a deleted record fails visibly. Finally, update the sync record at the start and end of handle().

If you catch an exception to add context, log it and rethrow it, or call $this->fail($exception). Either way Laravel sees the failure and applies your retry rules.

use Illuminate\Support\Facades\Log;
use Throwable;

public function handle(): void
{
    $order = Order::findOrFail($this->orderId);
    $sync = OrderSync::firstOrCreate(['order_id' => $order->id]);

    $sync->update([
        'status' => 'processing',
        'attempts' => $sync->attempts + 1,
        'last_attempt_at' => now(),
    ]);

    try {
        // Send $order to the external system with a stable reference.
    } catch (Throwable $exception) {
        $sync->update(['last_error' => $exception->getMessage()]);
        Log::error('Order sync failed.', ['order_id' => $order->id]);

        throw $exception;
    }

    $sync->update(['status' => 'synced', 'synced_at' => now()]);
}

Log the order reference, endpoint, and response status. Leave passwords, API tokens, and payment details out of the log context.

4. Record terminal failures in the failed() method

Define a failed() method on the job. Laravel calls it after the final attempt and passes the exception from that attempt.

If the job ran out of attempts or timed out instead, the exception is a MaxAttemptsExceededException or a TimeoutExceededException. Write the outcome to the sync record so support staff can filter on it.

public function failed(?Throwable $exception): void
{
    OrderSync::where('order_id', $this->orderId)->update([
        'status' => 'failed',
        'last_error' => $exception?->getMessage(),
    ]);
}

Laravel builds a fresh job instance before calling failed(), so changes made to properties inside handle() are lost. Persist any state you need in the database.

5. Alert on every failure

Then register a Queue::failing listener in AppServiceProvider::boot(). It receives a JobFailed event with the job and the exception. Send one alert to Slack, email, or your error tracker for every sync that fails.

use Illuminate\Queue\Events\JobFailed;
use Illuminate\Support\Facades\Queue;

Queue::failing(function (JobFailed $event) {
    // $event->job, $event->exception
});

If you use the failover queue driver, also listen for the QueueFailedOver event. Laravel dispatches it when a queue connection fails and a job moves to the next connection. Without a listener, a degraded primary queue goes unnoticed.

6. Retry failed jobs and prune old ones on purpose

  • List the stored failures with php artisan queue:failed.
  • Retry one failed job with php artisan queue:retry <job-id>.
  • Requeue every failed job with php artisan queue:retry all, but fix the cause first. Otherwise the same jobs fail again.
  • Delete records older than seven days with php artisan queue:prune-failed --hours=168. Schedule it only after the alert from step 5 works, because pruned records are gone.

If support staff handle retries, add an admin screen that lists records with a failed status and re-dispatches one order at a time.

Make the sync safe to run twice

A retry reruns handle() from the top. Laravel can also process a job twice when the worker --timeout exceeds the connection’s retry_after value.

The destination may also have accepted a request whose response never reached Laravel. Write with an upsert keyed on an external ID or an idempotency key, so a duplicate run updates the existing record.

7. Monitor workers and queue depth

A job failure is only one way Laravel sync failures go quiet. For example, a stopped worker leaves jobs pending with nothing in failed_jobs.

  • Run workers under Supervisor or an equivalent process manager so they restart after they exit.
  • Schedule queue:monitor with the queues to watch and a --max threshold, and listen for the QueueBusy event it fires.
  • Also use Laravel Horizon for a dashboard of throughput and failures. Horizon manages Redis queues only.

8. Reconcile what the queue cannot see

A scheduled command compares your records with the destination system. It catches Laravel sync failures that never reached the queue, which no failed-job tooling can detect.

Give the schedule entry withoutOverlapping() so two runs never process the same record. The command should:

  1. Find records not marked as synced after a set window, or changed after synced_at.
  2. Check whether each record already exists in the destination system.
  3. Dispatch the missing or incomplete ones again, using the original reference.
  4. Record the result on the sync record.
  5. Alert the team if the same record keeps failing.

For syncs that must not be lost, write an outbox row in the same database transaction as the data change and dispatch from that table. Laravel’s after_commit option delays dispatch until the transaction commits.

However, a crash between the commit and the dispatch can still lose the job, which is the gap an outbox row closes. That is our reading of how dispatch works, not a documented Laravel guarantee.

What should you set up first?

Start with the cheap fixes for Laravel sync failures. Set Tries and Backoff, remove any try/catch that hides errors, and add the Queue::failing alert. Then add worker monitoring.

Build reconciliation last, since it takes the most design effort and covers the failures the other steps miss. If your sync moves orders, stock, or payments between systems, Stagebit’s Laravel development team can review the design with you.

Was this answer helpful?

Your feedback helps us improve our answers.

Still need help?

Questions about failed syncs in Laravel?

If you're weighing how to catch failed or missing syncs in your Laravel app, we're happy to walk through what you're seeing and what your options are.

Talk to Laravel Experts