
Stop One User From Hogging Your Laravel Queue
The Problem I Ran Into I was building an AI image generation service. Users submit prompts, jobs go into a Laravel queue, workers process them. Simple enough - until one power user submitted 50 jobs at once. Result? Everyone else waited. The queue was FIFO, and that one user owned it. Queue: [A1][A2][A3]...[A50][B1][B2][C1] User B and C wait for ALL 50 of User A's jobs to finish. I needed fair distribution - not "first come first served", but "everyone gets a turn". That's what laravel-balanced-queue does. How It Works The package splits the queue into partitions (one per user/tenant) and rotates between them: Partition A: [A1][A2][A3]...[A50] Partition B: [B1][B2] Partition C: [C1][C2] Execution: A1 → B1 → C1 → A2 → B2 → C2 → A3 → ... Three strategies available: round-robin (recommended) — strict A→B→C→A→B→C rotation random — stateless, great for high load smart — boosts smaller queues, prevents starvation Plus concurrency limiting per partition - e.g., max 2 AI jobs per user simultan
Continue reading on Dev.to
Opens in a new tab




