惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
GbyAI
GbyAI
Engineering at Meta
Engineering at Meta
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
H
Hackread – Cybersecurity News, Data Breaches, AI and More
WordPress大学
WordPress大学
博客园_首页
美团技术团队
H
Help Net Security
MongoDB | Blog
MongoDB | Blog
宝玉的分享
宝玉的分享
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
J
Java Code Geeks
A
About on SuperTechFans
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
IT之家
IT之家
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
B
Blog
雷峰网
雷峰网
爱范儿
爱范儿

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Stop Crashing 3rd Party APIs: Throttling Laravel Jobs 🚦
Prajapati Pa · 2026-05-04 · via DEV Community

The API Rate Limit Catastrophe

In modern B2B SaaS development at Smart Tech Devs, your application rarely lives in isolation. You constantly communicate with external services: billing via Stripe, CRM syncing via Salesforce, or email campaigns via Resend. The architectural trap occurs when you combine the immense speed of Laravel Queues with the strict rate limits of these third-party APIs.

If you dispatch 5,000 "Sync Customer" background jobs, your Laravel Horizon workers will attempt to execute them as fast as your CPU allows. If the third-party API only allows 50 requests per minute, your first 50 jobs will succeed, and the next 4,950 will instantly crash with an HTTP 429: Too Many Requests error. This floods your failed jobs table, triggers false alarms in Sentry, and breaks your data synchronization.

The Enterprise Solution: Redis Job Middleware

To architect durable background processing, we must teach our queue workers to respect external boundaries. We achieve this by applying Rate Limiting Middleware directly to our queued jobs using Redis.

Instead of the job crashing when an API limit is reached, the middleware safely intercepts the job, pauses it, and releases it back onto the queue to be attempted again later when the rate limit has reset.

Step 1: Defining the Rate Limiter

First, we define our external API's strict speed limit in the boot method of our AppServiceProvider.


namespace App\Providers;

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

class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        // Define a strict limit: Max 50 requests per minute
        RateLimiter::for('salesforce-api', function ($job) {
            return Limit::perMinute(50);
        });
    }
}

Step 2: Applying Middleware to the Job

Next, we attach this specific rate limiter to our Job class using the middleware() method. We also configure how long the job should wait before retrying if it gets throttled.


namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\Middleware\RateLimited;

class SyncCustomerToSalesforce implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $tenant;

    // Allow the job to be retried for up to 12 hours
    public $retryUntil;

    public function __construct($tenant)
    {
        $this->tenant = $tenant;
        $this->retryUntil = now()->addHours(12);
    }

    /**
     * Get the middleware the job should pass through.
     */
    public function middleware(): array
    {
        // 1. Apply the Redis limiter we defined in the provider
        // 2. If throttled, release the job back to the queue with a 60-second delay
        return [
            (new RateLimited('salesforce-api'))->dontRelease()->releaseAfterMinutes(1)
        ];
    }

    /**
     * Execute the job (Safe from 429 errors!)
     */
    public function handle(): void
    {
        // Perform the external API HTTP request here...
        // We guarantee this will only execute 50 times per minute globally.
    }
}

The Architectural ROI

By implementing Redis-backed job throttling, you transform chaotic API integrations into perfectly paced, resilient data pipelines. You eliminate 429 error noise from your logs, protect your vendor API reputation, and guarantee that massive data syncs complete successfully, even if it takes hours to safely drip-feed the data.