Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › API rate limiting

Rate-Limited APIs and Laravel Queues: Control API Traffic Without Starving Other Jobs

By Freedom251 Team · · 4 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To keep Laravel queue jobs within an external API’s quota, define a named limiter with RateLimiter::for() and attach IlluminateQueueMiddlewareRateLimited to the jobs that call that API. The limiter key must match the quota the provider actually enforces: if several job types share one credential-wide cap, they must share one limiter key.

This controls request rate; it does not guarantee that unrelated jobs or queues will be scheduled fairly. Queue layout and worker allocation remain separate decisions.

As an Amazon Associate I earn from qualifying purchases.

How Laravel rate limiting works for queued jobs

Laravel’s queue middleware checks a named rate limiter before a job runs. When the limit has been reached, the middleware releases the job back to the queue, optionally after a delay. The job can run later when capacity is available.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The limiter is registered through RateLimiter::for(), and the job returns a RateLimited instance from its middleware() method. Laravel’s official Queues documentation for Laravel 13.x describes this pattern, including keys segmented by customer.

Choose a limiter key that reflects the provider’s quota

The key determines which jobs share a bucket. A per-customer key makes sense if the API grants each customer a separate quota. If the provider limits requests by account, credential, or shared service bucket, use a key representing that shared limit across every job class that consumes it. A key that is too narrow can let the combined traffic exceed the provider’s cap.

For example, this illustrative registration applies a limit of 50 per minute per account. The value is framework-style example code, not a recommendation about any particular provider’s quota:

use IlluminateCacheRateLimitingLimit;
use IlluminateSupportFacadesRateLimiter;

RateLimiter::for('partner-api', function (object $job) {
    return Limit::perMinute(50)->by($job->account->id);
});

If the provider applies a single credential-wide limit, replace the account-specific key with a stable shared key used by every relevant job. Avoid using a job ID or job class as the key unless the provider itself enforces a separate quota on that basis.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Attach the limiter to the API-calling job

Return the middleware from the job’s middleware() method:

use IlluminateQueueMiddlewareRateLimited;

public function middleware(): array
{
    return [new RateLimited('partner-api')];
}

The name passed to RateLimited must match the name registered with RateLimiter::for(). Apply the middleware to the jobs that consume that quota; jobs using a different provider quota should use a corresponding limiter.

Set the delay and retry budget together

A rate-limited release still consumes a job attempt. Laravel states in its official Laravel 13.x queue documentation: “Releasing a rate limited job back onto the queue will still increment the job’s total number of attempts.” If a job spends a long time waiting for capacity, a small attempt budget can be exhausted before it gets a chance to call the API.

  • Set tries or MaxExceptions to values that accommodate the expected wait and other retry causes.
  • Consider retryUntil when a time boundary is more appropriate than a fixed number of attempts; make that window long enough for realistic provider throttling.
  • Use releaseAfter(seconds) to choose a fixed release delay when needed. Laravel also calculates a suitable delay from the limiter duration by default.
  • Do not assume that a custom delay automatically tracks an API’s reset time. The Laravel documentation establishes the middleware’s delay options, but does not prescribe how to parse a particular provider’s Retry-After response.

For example, Laravel documents releaseAfter(60) as a delay option. Choose a value based on the provider’s quota window and the application’s retry policy rather than treating that example as a universal interval.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the middleware that matches the problem

Option Use it for Key considerations
RateLimited Enforcing a named, cache-backed request-rate limit. Cache configuration, shared-key design, release delay, and retry budget.
RateLimitedWithRedis Rate limiting in a Redis-based deployment. Confirm Redis connection and deployment setup. Laravel describes it as more efficient than the basic rate-limiting middleware.
WithoutOverlapping Preventing simultaneous jobs from operating on the same keyed resource. Choose the lock key, lock expiration, release delay, and attempt budget. It does not enforce an API requests-per-window quota.

Laravel documents both rate limiting and overlap prevention in its queue middleware guidance. They solve different problems and can be combined when a job must both respect an API quota and avoid concurrent changes to a resource.

For the Redis-specific option, see the Laravel API reference for RateLimited (12.x) and the queue documentation for middleware guidance. Verify that your application’s Redis configuration and middleware use the intended connection.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Rate limiting is not a fairness guarantee

RateLimited controls whether a job may proceed under a named quota and releases it when capacity is unavailable. The cited Laravel documentation does not promise fair scheduling across queues, worker pools, or unrelated jobs. A delay changes when the rate-limited job becomes eligible to run; it does not by itself determine which eligible job a worker selects next.

If a busy API queue is competing with unrelated work, address that at the queue and worker level: consider separating queues and allocating workers deliberately. Treat those as deployment choices, not a guarantee supplied by the rate-limiting middleware.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Common implementation mistakes

  • Using separate buckets for one shared provider quota: job classes or individual jobs can collectively exceed a cap if each has an independent key. Give them a common key when the API limit is shared.
  • Allowing releases to exhaust attempts: every release caused by the middleware counts as an attempt. Configure an adequate attempt limit or a suitable retryUntil boundary.
  • Retrying too quickly: Laravel provides a delay based on the limiter duration by default and allows a custom delay. Releasing repeatedly is not cost-free because each release consumes an attempt.
  • Confusing exceptions with quota enforcement: ThrottlesExceptions addresses repeated exceptions, whereas RateLimited enforces a defined rate limit. They may be useful together, but they react to different conditions.
  • Using overlap prevention as an API quota: WithoutOverlapping prevents concurrent work on a keyed resource; it does not enforce a requests-per-window cap.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

API rate limitingLaravelLaravel queuesPHPRedis

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.