Start free trial
Start free trial Log in

14-day free trial. No credit card.

Monitoring rate limits in Laravel

Track 429s, identify misbehaving consumers, and use rate-limit state as an early-warning signal for attacks and bad integrations.

  • Guide
  • 3 min read

How do I monitor rate limits in Laravel?

Track 429 response rate per route in your APM. Laravel's throttle middleware returns 429 when limits are hit, and a spike indicates a misbehaving consumer, bot, or attack. Drill in by IP, API key, or user_id to find the source. For distributed setups across multiple servers, back the rate limiter with a shared cache store (usually Redis) so limits are enforced globally, not per-server. NightOwl counts 429s in each route's 4XX column; open the route and filter to 4xx to see the throttled requests.

Updated

A 429 is one of the most overlooked signals in a Laravel app. Most teams set up throttling once, confirm it returns the right status code, and never look at it again. But the rate of 429s, broken down by route, is one of the earliest warnings you get for a whole class of problems: credential stuffing, a customer's integration stuck in a retry loop, a bot farming password resets.

Setting up Laravel rate limits

app/Providers/AppServiceProvider.php

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

public function boot(): void
{
    RateLimiter::for('api', function ($request) {
        $key = $request->header('X-Api-Key') ?? $request->ip();
        return Limit::perMinute(100)->by($key);
    });

    RateLimiter::for('login', function ($request) {
        return [
            // 5 per minute per IP
            Limit::perMinute(5)->by($request->ip()),
            // 20 per minute per email (prevents targeted stuffing)
            Limit::perMinute(20)->by($request->input('email')),
        ];
    });
}

routes/api.php

php
Route::middleware('throttle:api')->group(function () {
    Route::get('/users', [UserController::class, 'index']);
    Route::post('/orders', [OrderController::class, 'store']);
});

Route::post('/login', LoginController::class)
    ->middleware('throttle:login');

Track 429s in your APM

429 responses show up in your request telemetry. The value is per-route grouping:

  • /api/* 429 spike → a consumer's retry logic is broken, or an API key is compromised
  • /login 429 spike → credential stuffing attack
  • /password/reset 429 spike → someone farming password reset emails
  • /api/webhooks/* 429 spike → your upstream is retrying because processing is slow

Log rate-limit hits with context

Custom middleware that logs 429s

php
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class LogRateLimitHits
{
    public function handle(Request $request, Closure $next)
    {
        $response = $next($request);

        if ($response->status() === 429) {
            Log::warning('Rate limit hit', [
                'route' => $request->route()?->uri(),
                'method' => $request->method(),
                'ip' => $request->ip(),
                'api_key' => $request->header('X-Api-Key'),
                'user_id' => auth()->id(),
                'retry_after' => $response->headers->get('Retry-After'),
            ]);
        }

        return $response;
    }
}

It has to run outside the throttle middleware to see the 429, so append it to the web or api group in bootstrap/app.php; group middleware runs before route middleware like throttle:api.

Distributed rate limiting with Redis

On a multi-server fleet, the rate limiter is only as shared as the cache store behind it. The file store gives each server its own counter. The database store (the default since Laravel 11) and Redis are shared, and Redis is the usual choice once throttled traffic is heavy:

.env

Terminal
CACHE_STORE=redis
REDIS_HOST=your-redis-host
REDIS_PORT=6379

# Optional: give rate limits their own store so general
# cache pressure can't evict them (see config/cache.php below)

config/cache.php

php
// The store the RateLimiter uses (defaults to the default store)
'limiter' => 'limiter',

'stores' => [
    'limiter' => [
        'driver' => 'redis',
        'connection' => 'limiter', // a connection under 'redis' in config/database.php
    ],
    // ...your existing stores
],

With a shared store the counter is global: 100 req/min on a 3-server fleet means 100 total, not 300. The standard throttle middleware reads the count and then increments it, so a burst can slip slightly past the limit. Calling $middleware->throttleWithRedis() in bootstrap/app.php switches it to Laravel's Redis throttle, which checks and increments atomically.

Alerting thresholds

Route pattern Alert at Likely cause
/login10+ 429s/minCredential stuffing
/api/*5x baseline sustained 10minRunaway client retries
/password/*3+ 429s/minPassword-reset farming
/api/webhooks/*any sustainedUpstream retry storm from slow processing

NightOwl won't page you on any row of this table. A 429 lands in its route's 4xx count, and NightOwl alerts only on new exceptions and on requests over a duration threshold.

The proxy trap

One subtle failure mode: if your app sits behind a load balancer or CDN and you key the limiter by $request->ip(), every request can look like it came from the proxy's IP. The limiter then throttles all your users as if they were one client, or (if the proxy rotates IPs) never throttles anyone. Laravel only reads the real client address from X-Forwarded-For when you've configured TrustProxies correctly. So if your rate limits behave nothing like you expect in production but work fine locally, check trusted proxies before you touch the limit values themselves.

Find the client behind each 429

Every 429 counts toward its route's 4xx column on the Requests page. Filter the route to 4xx and open a throttled request to see the IP, the user and the headers of the client that hit the ceiling.

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

How do I monitor rate limits in Laravel?

Laravel's throttle middleware returns a 429 response when a limit is exceeded. Track the 429 rate per route in your APM. A spike usually indicates a specific consumer retrying aggressively or a bot; drill into the rate-limited requests by IP, API key, or user_id to find the source.

What's the difference between Laravel's throttle middleware and the RateLimiter facade?

The throttle middleware (Route::middleware('throttle:60,1')) is the high-level HTTP-routing use case: 60 requests per minute per signed-in user, or per IP for guests. The RateLimiter facade is the programmatic API you use in controllers, jobs, or anywhere else you want to enforce a limit outside HTTP. Both ultimately use the same underlying Illuminate\Cache\RateLimiter.

How do I rate-limit per API key instead of per IP?

In a service provider, register a named limiter keyed by the API key: RateLimiter::for('api', fn($request) => Limit::perMinute(100)->by($request->header('X-Api-Key') ?? $request->ip())). Then apply via throttle:api in your route group.

Should I alert on high 429 rates?

Yes, but at the right threshold. A few 429s per minute are normal (someone spamming a form). Alert when 429 rate jumps 5x+ above baseline for 10+ minutes. That's a misbehaving integration or attack. Route-level alerts beat global: a spike on /api/login means credential stuffing, on /api/webhooks/stripe means your webhook handler is slow. NightOwl counts 429s per route but doesn't alert on them, so a baseline alert like this needs your metrics stack or a scheduled query.

How do I know if my rate limits are too aggressive?

Track rate-limited users/keys. If the same legitimate user or API key repeatedly hits your limits, they're either being throttled too hard or you're missing proper per-tier quotas. Look at the distribution. If 99% of traffic is well under the limit and 1% is being limited, the limits are probably fine. If 30% is being limited, they're too strict.

Can I use Redis for distributed rate limiting in Laravel?

Yes. Set CACHE_STORE=redis, or name a Redis store in the cache.limiter config key to use it for rate limits only. What multiple web servers need is a shared store: Redis and the default database store are both shared, while the file store gives each server its own counter and makes limits per-server (effectively 3x more permissive on a 3-server fleet). The standard throttle middleware checks the count and then increments it, so it isn't strictly atomic. For atomic Redis throttling, call $middleware->throttleWithRedis() in bootstrap/app.php.

How do I communicate rate-limit state to API consumers?

Laravel includes X-RateLimit-Limit and X-RateLimit-Remaining headers automatically on throttled routes, and adds Retry-After and X-RateLimit-Reset to every 429 it returns. Well-behaved clients read these and back off. Document these headers in your API docs so consumers can build proper backoff into their SDKs.

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 who hits your rate limits

Every 429 lands on its route, with the IP and user of the client behind it. No credit card needed.