Start free trial
Start free trial Log in

14-day free trial. No credit card.

Monitor Laravel queue latency

How to measure the time from dispatch to start, the queue signal that matters most.

  • Guide
  • 4 min read

How do I monitor Laravel queue latency?

Subtract the job payload's createdAt timestamp from the time a worker starts it; that delta is queue latency. Store it per queue, aggregate p95 over time to see trends, and run a scheduled check that alerts when the oldest pending job is older than the queue's target. Laravel doesn't aggregate this by default. NightOwl shows the queue wait before each job attempt in its trace timeline and charts processing time per job class (p50, p95, p99).

Updated

When a queue backs up, nobody gets an error. The password reset email just arrives four minutes late, by which point the user has requested three more. Queue latency is the delay between dispatching work and a worker actually starting it, and it's the part of background processing your users feel most directly, even though it never shows up as a failure. A healthy-looking queue with zero failed jobs can still be quietly ruining the experience if the wait time has crept up.

Latency vs runtime: the two halves

Perceived job delay = queue latency + job runtime. They're separate problems:

Problem Cause Fix
High queue latencyNot enough worker capacity for dispatch rateScale workers or split queues
High runtimeThe job itself is slow (DB, external API, computation)Optimize or decompose the job

Measuring latency yourself

Laravel fires JobProcessing when a worker picks up a job. Every queued payload includes createdAt, a Unix timestamp in seconds set at dispatch, so the resolution is one second. For a delayed job, the wait includes the delay you asked for. Register the listener in AppServiceProvider::boot():

app/Providers/AppServiceProvider.php

php
<?php

namespace App\Providers;

use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        Event::listen(function (JobProcessing $event) {
            $createdAt = $event->job->payload()['createdAt'] ?? null;

            if ($createdAt === null) {
                return;
            }

            DB::table('queue_latency')->insert([
                'queue' => $event->job->getQueue(),
                'job_class' => $event->job->resolveName(),
                'attempt' => $event->job->attempts(),
                'latency_ms' => max(0, (microtime(true) - $createdAt) * 1000),
                'started_at' => now(),
            ]);
        });
    }
}

On PostgreSQL, aggregate with percentile_cont(0.95) WITHIN GROUP (ORDER BY latency_ms), grouped per queue per minute. A retried job keeps its original createdAt, so filter on attempt = 1 if you only want the first wait.

Per-queue SLOs

Assign each queue a latency target based on what it serves. These figures are starting points, not a standard:

Queue Work type SLO (p95)
transactionalPassword resets, 2FA codes< 3s
defaultUser notifications, light background work< 15s
indexingSearch index updates< 60s
batchNightly exports, bulk imports< 10m

Separate fast from slow

Mixing fast and slow jobs on the same queue with the same workers is a common cause of latency spikes. A 5-second job class that fires 100 times floods the queue and starves the sub-second email jobs behind it. Fix it by splitting queues and dedicating workers. Don't declare a public $queue property on the job: the Queueable trait already defines $queue, and redeclaring it with a default value is a fatal error. Call onQueue() in the constructor instead:

app/Jobs/SendPasswordResetEmail.php

php
public function __construct(public User $user)
{
    $this->onQueue('transactional');
}

app/Jobs/GenerateMonthlyReport.php

php
public function __construct(public int $month)
{
    $this->onQueue('batch');
}

Supervisor needs the absolute path to artisan, and a process_name containing %(process_num) when numprocs is above 1. A worker's --timeout must be shorter than the connection's retry_after (90 seconds by default in config/queue.php), or a long job gets handed to a second worker while the first is still running it. The batch worker below uses a separate redis-long connection with retry_after set to 660:

supervisord config

ini
[program:laravel-transactional-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/app/artisan queue:work redis --queue=transactional --sleep=0 --tries=3
autostart=true
autorestart=true
numprocs=5
stopwaitsecs=60

[program:laravel-batch-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/app/artisan queue:work redis-long --queue=batch --sleep=3 --timeout=600 --tries=1
autostart=true
autorestart=true
numprocs=2
stopwaitsecs=660

Alerting on backlog

Alert on the age of the oldest pending job rather than the count. Laravel 12's queue drivers expose creationTimeOfOldestPendingJob(), which returns a Unix timestamp (or null for an empty queue) and skips delayed jobs. Schedule the check in routes/console.php:

routes/console.php

php
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\Facades\Schedule;

Schedule::call(function () {
    $oldest = Queue::connection('redis')
        ->creationTimeOfOldestPendingJob('transactional');

    if ($oldest === null) {
        return;
    }

    $ageSeconds = now()->getTimestamp() - $oldest;

    if ($ageSeconds > 10) {
        // Swap for a notification to your on-call channel.
        Log::critical('Transactional queue lag', ['age_seconds' => $ageSeconds]);
    }
})->everyMinute()->name('check-transactional-queue-lag')->withoutOverlapping();

For a count-based check, php artisan queue:monitor redis:transactional --max=100 dispatches a QueueBusy event when the queue reaches 100 jobs. Schedule it every minute and listen for the event to send the alert.

Point-in-time isn't enough

The trap with queue monitoring is watching the current backlog. A dashboard that shows "0 pending jobs right now" looks reassuring and tells you nothing about the 9am spike where the transactional queue sat at 40 seconds of lag for twenty minutes. By the time you look, it has drained. Latency is a distribution over time, not a number you glance at. The queue_latency table above gives you p95 wait per queue over hours and days, so the recurring 9am problem shows up as a shape on a graph. On Redis, Horizon's dashboard shows only the current wait, not its history.

NightOwl covers the other half and the per-job view. Each job class page charts processing time (avg, p50, p95, p99) alongside processed, released and failed attempts, and the attempts list filters to runs at or above p95. Open an attempt and the trace timeline shades the gap before it started; hover it to read the queue wait for that attempt. It doesn't chart wait time per queue or per class, so keep the listener for trends.

See how long each job waited before it ran

NightOwl's trace timeline shows the queue wait before every job attempt, and each job class page charts processing time at p50, p95 and p99. Set a duration threshold for a job class, and a run that crosses it opens a performance issue and sends an alert.

No credit card needed.

Terminal
composer require nightowl/agent
php artisan nightowl:install
php artisan nightowl:agent

Frequently asked questions

Anything else, write to support@usenightowl.com

What is queue latency in Laravel?

The time between when a job is dispatched and when a worker actually starts processing it. Also called queue wait time or time-to-start. Distinct from job runtime (how long handle() takes once it starts). High queue latency means dispatched jobs pile up waiting for worker capacity. Users see delayed emails, outdated search indexes, unposted webhooks.

How do I measure Laravel queue latency?

Every queued job's payload carries a createdAt Unix timestamp set at dispatch. Listen for JobProcessing, subtract createdAt from the current time, and store the result per queue and job class. Laravel doesn't aggregate this for you. NightOwl records the dispatch and every attempt, and its trace timeline shows the queue wait before each attempt, but it doesn't chart wait time per queue or per class.

What's a healthy Laravel queue latency?

Depends on the queue. User-facing work (password reset email, transactional mail) should be under 5 seconds p95 end-to-end. Background work (index updates, report generation) tolerates 30-60 seconds. Batch work (overnight sync) can tolerate minutes. Set a per-queue target and have a scheduled check alert you when the oldest pending job is older than that target.

Why is my Laravel queue lagging?

Four common causes: (1) not enough workers for current dispatch rate (scale up workers), (2) one job class with a long runtime blocking a shared queue (split it to its own queue), (3) a downstream dependency failing and triggering retries (releases eat worker capacity), (4) worker crashes not getting supervised correctly (check Supervisor/systemd).

Should I use separate Laravel queues for fast and slow jobs?

Yes, almost always. Put fast user-facing work (emails, notifications) on a dedicated queue such as 'transactional' and slow background work (reports, bulk updates) on one such as 'batch'. Run separate workers per queue so a long job class never starves the fast queue. Set different timeouts and retry strategies per queue.

How does queue latency differ from job runtime?

Queue latency = dispatched_at to started_at. Job runtime = started_at to completed_at. Total perceived latency = latency + runtime. Users only care about total; you need to distinguish because the fixes are different. High latency = more workers. High runtime = optimize the job.

Does Horizon show queue latency?

Partly. Horizon's dashboard shows the current wait per queue and the longest wait, and the waits setting in config/horizon.php can notify you when a queue's wait passes a threshold. Its Metrics page charts throughput and runtime, not wait, and Horizon only runs on Redis queues. For wait trends or per-job wait percentiles on any driver, record createdAt yourself in a JobProcessing listener.

How do I alert on queue backlog growth?

Two approaches. Count-based: php artisan queue:monitor with --max fires a QueueBusy event when a queue reaches that many jobs. Time-based: a scheduled check compares the oldest pending job's age with your target. Time-based is usually better because a backlog of 10 jobs on a slow queue can still miss the target, while 10K jobs on a fast queue may be fine. NightOwl doesn't alert on queue backlog or wait time; its job alerts are duration thresholds on processing time.

Flat pricing, whatever your traffic does

Every plan starts with a 14-day free trial. No credit card needed.

Hobby
$5 a month

One app for a side project. Issues and alerts, with a 14-day dashboard window.

Start my 14-day trial
TeamRecommended
$15 a month

Up to 3 apps and 5 people per team. Full history, the MCP server, data clearing and agent health.

Start my 14-day trial
Agency
$69 a month

Unlimited client apps and people, one overview of every app, and apps you can hand over.

Start my 14-day trial

Related

See queue wait times on your own jobs

Install the agent and every job attempt shows how long it sat in the queue. No credit card needed.