Query the size of a Laravel queue

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Querying the Size of a Laravel Queue: Getting Real-Time Statistics

I am planning to use Laravel Queue, and now I am doing some research: Is it possible to get the size of a Laravel queue? Even better, can I get some statistics of a Laravel queue?

As developers building scalable applications with Laravel, managing background jobs efficiently is crucial. Knowing how many jobs are waiting, processing, or have failed provides essential visibility into the health and performance of your system. The short answer is: Yes, it is absolutely possible to query the size and statistics of a Laravel queue, but the method you use depends entirely on the queue driver you have configured.

This post will dive deep into how Laravel queues manage their data and provide practical methods for monitoring your job queues.


Understanding How Laravel Queues Store Data

Laravel itself provides an abstraction layer (the Queue facade) to handle the complexity of sending jobs. However, the actual storage mechanism—and therefore the method for querying statistics—is dictated by the underlying driver you choose.

The most common drivers are:

  1. Database: Jobs are stored in a dedicated table within your application's database.
  2. Redis: Jobs are stored as lists or streams within the Redis cache.
  3. Beanstalkd/SQS: Jobs are pushed to an external message broker.

Since Laravel is designed to be flexible, it doesn't enforce a single method for querying; instead, it delegates that responsibility to the chosen driver.

Method 1: Querying the Database Driver (The Standard Approach)

If you are using the default database driver, your queue entries are stored in a table, typically named jobs. To get the size of the queue, you simply query this table. This is the most direct way to see the backlog.

Here is an example of how you would calculate the total number of pending jobs:

use Illuminate\Support\Facades\DB;

class QueueMonitor
{
    public function getQueueSize()
    {
        // Assuming a standard setup where jobs are stored in the 'jobs' table
        $count = DB::table('jobs')->where('status', 'pending')->count();
        return $count;
    }

    public function getFailedJobsCount()
    {
        // Count jobs that have failed (useful for error tracking)
        $count = DB::table('jobs')->where('status', 'failed')->count();
        return $count;
    }
}

This approach is straightforward and leverages standard Eloquent/Query Builder functionality. For complex systems, ensuring data integrity in your database schema is paramount, which aligns with the robust architecture promoted by services like those found on laravelcompany.com.

Method 2: Querying Redis or External Brokers

When using high-performance drivers like Redis, you interact directly with the Redis instance rather than a relational database table. In this scenario, you would use Redis commands to check the length of the relevant queue list (e.g., checking the length of a Redis list named laravel_queue).

While Laravel abstracts this away during job processing, for advanced monitoring, direct interaction is necessary:

use Illuminate\Support\Facades\Redis;

class RedisQueueMonitor
{
    public function getRedisQueueSize(string $queueName)
    {
        // Use the LENGTH command to check the size of the Redis list
        $size = Redis::lrange($queueName, 0, -1); // A more complex way depending on setup might be needed for true queue length checks.
        return count($size);
    }
}

Note: The exact command depends heavily on how you have configured your queue binding within the Laravel application.

Best Practices for Queue Statistics

Relying solely on the queue size is insufficient for true operational awareness. A senior developer always looks beyond simple counts. For comprehensive statistics, focus on these metrics:

  1. Pending Jobs: The total number of jobs waiting to be processed (the backlog).
  2. Failed Jobs: The count and details of jobs that threw exceptions and require manual intervention.
  3. Processing Time: Tracking how long an average job takes to complete can reveal bottlenecks in your application logic or external service dependencies.

By implementing custom monitoring endpoints that query these underlying data stores—whether it’s the database, Redis, or a dedicated monitoring service—you gain full control over your job workflow visibility. Mastering this level of introspection is key to building resilient systems on top of Laravel.

Conclusion

In summary, querying the size of a Laravel queue is entirely feasible. The mechanism you employ depends on your chosen driver: direct SQL queries for database setups, or specific commands for Redis and other brokers. By understanding these underlying data structures and applying proper monitoring practices, you can transform raw queue data into actionable insights, ensuring your background processing is always robust and efficient.