Laravel Job Batching, Chaining &amp; Rate Limiting | Mohamed Said       [Skip to content](#main)  [ ![](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MH.png) Mohamed SaidLaravel Backend Engineer ](https://www.msaied.com/public) - [Home](https://www.msaied.com/public)
- [Projects](https://www.msaied.com/public/projects)
- [Articles](https://www.msaied.com/public/articles)
- [Certificates](https://www.msaied.com/public/certificates)
- [About](https://www.msaied.com/public#about)

           [  Contact](https://www.msaied.com/public#contact) Menu 

Menu
----

Close 

 - [HomeStart here](https://www.msaied.com/public)
- [ProjectsCase studies](https://www.msaied.com/public/projects)
- [ArticlesEngineering notes](https://www.msaied.com/public/articles)
- [CertificatesCredentials](https://www.msaied.com/public/certificates)
- [AboutHow I work](https://www.msaied.com/public#about)
- [ContactGet in touch](https://www.msaied.com/public#contact)

  [Start a conversation](https://www.msaied.com/public#contact) [WhatsApp](https://wa.me/201094619204) [Email](mailto:hello@msaied.com) 

 1. [Home](https://www.msaied.com/public)
2. /
3. [Articles](https://www.msaied.com/public/articles)
4. /
5. Job Batching, Chaining, and Rate-Limited Middleware in Laravel Queues

 Job Batching, Chaining, and Rate-Limited Middleware in Laravel Queues
======================================================================

 Go beyond basic dispatching: learn how to compose Laravel job batches, build reliable chains, and throttle throughput with rate-limited middleware — all with production-ready patterns.

 ![](https://cdn.msaied.com/01M22N44A70A5MC2S599JP0MPH.webp) [Mohamed Said](https://www.msaied.com/public#person) Published 14 Jun 2026 · Updated 14 Jun 2026 · 3 min read

ShareCopy linkCopied

 ![Job Batching, Chaining, and Rate-Limited Middleware in Laravel Queues](https://cdn.msaied.com/167/07cf94b1aa8fcead662b9cd5af47acb6.png) 

  On this page +1. [Job Batching, Chaining, and Rate-Limited Middleware in Laravel Queues](#job-batching-chaining-and-rate-limited-middleware-in-laravel-queues)
2. [Batches: Parallel Work With a Shared Lifecycle](#batches-parallel-work-with-a-shared-lifecycle)
3. [Chains: Sequential Pipelines With Shared Context](#chains-sequential-pipelines-with-shared-context)
4. [Rate-Limited Job Middleware](#rate-limited-job-middleware)
5. [Takeaways](#takeaways)

 Job Batching, Chaining, and Rate-Limited Middleware in Laravel Queues
---------------------------------------------------------------------

Laravel's queue system is deceptively deep. Most teams dispatch individual jobs and call it done. But production workflows demand composition: run a set of jobs in parallel, then trigger a follow-up only when all succeed, and never hammer a third-party API faster than its rate limit allows. Laravel gives you all three primitives — batches, chains, and job middleware — and combining them correctly is where the real power lives.

---

### Batches: Parallel Work With a Shared Lifecycle

A batch dispatches multiple jobs concurrently and exposes callbacks for completion, failure, and progress.

```php
use Illuminate\Support\Facades\Bus;

$batch = Bus::batch([
    new ProcessInvoice($invoice1),
    new ProcessInvoice($invoice2),
    new ProcessInvoice($invoice3),
])
->then(fn (Batch $batch) => SendBatchSummary::dispatch($batch->id))
->catch(fn (Batch $batch, Throwable $e) => Log::error('Batch failed', [
    'batch' => $batch->id,
    'error' => $e->getMessage(),
]))
->finally(fn (Batch $batch) => Cache::forget('invoices:processing'))
->name('Invoice Processing')
->allowFailures() // don't cancel remaining jobs on a single failure
->dispatch();

```

Store `$batch->id` if you need to poll progress from a UI. `$batch->progress()` returns 0–100 based on processed job count.

**Important:** Every job in a batch must use the `Batchable` trait, and you should check `$this->batch()->cancelled()` at the start of `handle()` to respect early cancellation.

```php
use Illuminate\Bus\Batchable;
use Illuminate\Contracts\Queue\ShouldQueue;

class ProcessInvoice implements ShouldQueue
{
    use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function handle(): void
    {
        if ($this->batch()?->cancelled()) {
            return;
        }

        // ... process
    }
}

```

---

### Chains: Sequential Pipelines With Shared Context

Chains execute jobs one after another; if any job fails, the rest are abandoned.

```php
Bus::chain([
    new ValidateOrder($order),
    new ChargePayment($order),
    new FulfillOrder($order),
    new SendConfirmationEmail($order),
])
->catch(fn (Throwable $e) => $order->markFailed($e->getMessage()))
->dispatch();

```

You can mix batches inside chains for hybrid workflows:

```php
Bus::chain([
    new PrepareExport($report),
    Bus::batch([
        new ExportChunk($report, 0),
        new ExportChunk($report, 1),
        new ExportChunk($report, 2),
    ]),
    new MergeExportChunks($report),
])->dispatch();

```

This pattern — prepare, fan-out in parallel, then merge — is a clean map-reduce for queue workers.

---

### Rate-Limited Job Middleware

Throttling at the job level is far more reliable than sleeping inside `handle()`. Laravel's `RateLimited` middleware uses the cache to enforce limits across all workers.

```php
use Illuminate\Queue\Middleware\RateLimited;

class SyncToStripe implements ShouldQueue
{
    public function middleware(): array
    {
        return [new RateLimited('stripe-sync')];
    }
}

```

Define the limiter in a service provider:

```php
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\RateLimiter;

RateLimiter::for('stripe-sync', fn () =>
    Limit::perMinute(60)->response(fn () =>
        // job is released back to the queue automatically
        null
    )
);

```

When the limit is hit, the job is released back with a calculated backoff — no wasted worker time, no dropped requests.

For per-tenant limits, key the limiter dynamically:

```php
public function middleware(): array
{
    return [new RateLimited('stripe-sync:' . $this->tenantId)];
}

```

---

### Takeaways

- Use `Bus::batch()` for parallel fan-out; always add `Batchable` and check for cancellation.
- Use `Bus::chain()` for sequential pipelines where order and dependency matter.
- Nest a batch inside a chain for map-reduce style workflows.
- Throttle third-party API jobs with `RateLimited` middleware — never `sleep()`.
- Key rate limiters per tenant or resource to avoid cross-tenant interference.
- Monitor batch progress via `$batch->id` and expose it to your UI for long-running operations.

- [laravel](https://www.msaied.com/public/articles?search=laravel)
- [queues](https://www.msaied.com/public/articles?search=queues)
- [jobs](https://www.msaied.com/public/articles?search=jobs)
- [async](https://www.msaied.com/public/articles?search=async)

 Frequently asked questions 
---------------------------

  What happens to a chain if one job in a nested batch fails?By default, a single failure in a batch cancels the batch and prevents subsequent chain steps from running. Use `-&gt;allowFailures()` on the batch if you want remaining batch jobs to continue, but note the chain's `catch` callback will still fire if the batch itself is marked as failed.

   Does rate-limited middleware work across multiple Horizon workers?Yes. The `RateLimited` middleware uses your configured cache driver as the shared counter, so limits are enforced globally across all worker processes and servers — as long as they share the same cache backend (Redis is recommended).

   Can I track batch progress in a Filament or Livewire UI?Yes. Store the batch ID in your database or session after dispatching, then poll `Bus::findBatch($id)` on a Livewire component using a `wire:poll` directive. The `$batch-&gt;progress()` method returns an integer 0–100 you can bind directly to a progress bar.

   ![Mohamed Said](https://cdn.msaied.com/01M22N44A70A5MC2S599JP0MPH.webp)About the author
----------------

[Mohamed Said](https://www.msaied.com/public#person)Senior Backend Engineer specializing in Laravel, scalable SaaS platforms, APIs, and cloud infrastructure. I build secure, high-performance web applications that help businesses grow.

[About](https://www.msaied.com/public#about) [GitHub ↗](https://github.com/EG-Mohamed) [LinkedIn ↗](https://www.linkedin.com/in/msaiedm/) [WhatsApp ↗](https://wa.me/201094619204) [Email Address ↗](mailto:hello@msaied.com) [My CV ↗](https://drive.google.com/file/u/0/d/1MF20IPRJyzfy32mhEutjL5EpSls0w2Q8/view)  

   [Previous articlePest Architecture Tests: Enforcing Clean Boundaries in Laravel Without a CI Nanny](https://www.msaied.com/public/articles/pest-architecture-tests-enforcing-clean-boundaries-in-laravel-without-a-ci-nanny) [Next articleCursor Pagination at Scale with Laravel Lazy Collections and Chunked Iteration](https://www.msaied.com/public/articles/cursor-pagination-at-scale-with-laravel-lazy-collections-and-chunked-iteration)  

   On this page
-------------

1. [Job Batching, Chaining, and Rate-Limited Middleware in Laravel Queues](#job-batching-chaining-and-rate-limited-middleware-in-laravel-queues)
2. [Batches: Parallel Work With a Shared Lifecycle](#batches-parallel-work-with-a-shared-lifecycle)
3. [Chains: Sequential Pipelines With Shared Context](#chains-sequential-pipelines-with-shared-context)
4. [Rate-Limited Job Middleware](#rate-limited-job-middleware)
5. [Takeaways](#takeaways)

 ###  Have a technical challenge?

 Tell me what you’re building. I reply within two working days.

[Start a conversation](https://www.msaied.com/public#contact) 

   Related articles
-----------------

 [ ![](https://cdn.msaied.com/740/cce86edc21eddcbdd2f2454fadaf9c70.png)  · 3 min read### The Pipeline Pattern in Laravel: Custom Pipelines Beyond Middleware

5 Oct 2026 ](https://www.msaied.com/public/articles/the-pipeline-pattern-in-laravel-custom-pipelines-beyond-middleware-1) [ ![](https://cdn.msaied.com/739/2d6897fdcdcf090613f96f72a64b8a78.png)  · 4 min read### MySQL Full-Text Search in Laravel: Indexes, Relevance Scoring, and Boolean Mode

4 Oct 2026 ](https://www.msaied.com/public/articles/mysql-full-text-search-in-laravel-indexes-relevance-scoring-and-boolean-mode) [ ![](https://cdn.msaied.com/738/073696a3fefe18bec825beec5ac658f5.png)  · 4 min read### Laravel Queue Rate-Limited Middleware: Throttling Jobs Without Losing Work

4 Oct 2026 ](https://www.msaied.com/public/articles/laravel-queue-rate-limited-middleware-throttling-jobs-without-losing-work) 

  Have a technical challenge?
----------------------------

Tell me what you’re building. I reply within two working days.

 [Discuss your project ↗](https://www.msaied.com/public#contact) 

  © 2026 Mohamed Said · Built with Laravel, meant to last.Senior Backend Engineer specializing in Laravel, scalable SaaS platforms, APIs, and cloud infrastructure. I build secure, high-performance web applications that help businesses grow.

 - [Home](https://www.msaied.com/public)
- [Articles](https://www.msaied.com/public/articles)
- [Certificates](https://www.msaied.com/public/certificates)
- [GitHub](https://github.com/EG-Mohamed)
- [LinkedIn](https://www.linkedin.com/in/msaiedm/)
- [WhatsApp](https://wa.me/201094619204)
- [Email Address](mailto:hello@msaied.com)
- [My CV](https://drive.google.com/file/u/0/d/1MF20IPRJyzfy32mhEutjL5EpSls0w2Q8/view)
- [Sitemap](https://www.msaied.com/public/sitemap.xml)
