← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Async Processing / Job Queues

performance PHP 5.0+ Intermediate

Also Known As

background jobs async tasks job queue processing

TL;DR

Deferring time-consuming work (emails, image processing, third-party API calls) to background workers via a queue, improving response times.

Explanation

Synchronous processing of slow operations (sending emails, resizing images, calling external APIs) directly in a web request increases response times and risks timeouts. Job queues (Laravel Queues, Symfony Messenger, RabbitMQ, Redis queues) accept a job description, store it durably, and process it asynchronously in a separate worker process. This reduces web response time to near-instant, improves resilience (failed jobs can be retried), and allows work to be distributed across multiple workers. The trade-off is eventual consistency and added infrastructure complexity.

Diagram

flowchart LR
    subgraph Synchronous - Slow
        REQ1[HTTP Request] --> PROC1[Process<br/>resize image<br/>5 seconds] --> RES1[Response<br/>after 5s]
    end
    subgraph Async - Fast
        REQ2[HTTP Request] --> QUEUE[Push to Queue<br/>immediately] --> RES2[Response<br/>50ms]
        QUEUE --> WORKER[Background Worker<br/>resizes image]
        WORKER --> NOTIFY[Notify user<br/>when done]
    end
    style RES1 fill:#f85149,color:#fff
    style RES2 fill:#238636,color:#fff

Common Misconception

Async processing always means using a message queue like RabbitMQ. Simple background processing can be achieved with database-backed queues (Laravel Queues, Symfony Messenger) or even cron-driven workers — a full message broker is only warranted when throughput or reliability requirements exceed what a database queue can provide.

Why It Matters

Moving slow operations — email sending, PDF generation, third-party API calls — off the HTTP request/response cycle keeps response times fast regardless of the work being done. Without async processing, one slow job can block a request thread for seconds.

Common Mistakes

  • Dispatching jobs to a queue but not running any queue workers — jobs sit queued and never process.
  • Putting too much serialised data in the job payload — pass IDs and re-fetch fresh data in the worker instead.
  • Not handling job failures with retries and dead-letter queues — failed jobs silently disappear.
  • Running queue workers without a process supervisor (Supervisor, Horizon) — workers die and no one notices.

Code Examples

✗ Vulnerable
// Synchronous — user waits for email + PDF + analytics:
function placeOrder(Order $o): void {
    $this->db->save($o);
    $this->mailer->sendConfirmation($o);  // 800ms
    $this->pdf->generateInvoice($o);      // 1200ms
    $this->analytics->track($o);          // 300ms
    // User blocked for 2.3s — all should be queued
}
✓ Fixed
// Dispatch heavy work to a queue — return immediately to the user
class OrderController {
    public function store(Request $req): JsonResponse {
        $order = Order::create($req->validated());

        // Don't process payment synchronously — queue it
        ProcessPayment::dispatch($order)->onQueue('payments');
        GenerateInvoice::dispatch($order)->onQueue('documents');
        SendConfirmationEmail::dispatch($order)->delay(now()->addSeconds(5));

        return response()->json(['id' => $order->id], 202); // Accepted
    }
}

// Worker processes jobs in the background
$ php artisan queue:work --queue=payments,documents,default

Added 15 Mar 2026
Edited 22 Mar 2026
Views 25
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
2 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 2 pings F 0 pings S 0 pings S 0 pings M 0 pings T 1 ping W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T
No pings yet today
No pings yesterday
Amazonbot 6 Unknown AI 3 ChatGPT 2 Google 2 Ahrefs 2 Perplexity 1
crawler 13 crawler_json 1 pre-tracking 2
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Medium
⚡ Quick Fix
Move any operation taking >200ms out of the HTTP request into a queue job — email, PDF generation, image resizing, API calls to slow third parties
📦 Applies To
PHP 5.0+ web queue-worker laravel symfony
🔗 Prerequisites
🔍 Detection Hints
Sending email inside HTTP request; PDF generation blocking response; slow third-party API call in request lifecycle
Auto-detectable: ✗ No blackfire laravel-debugbar
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✗ Manual fix Fix: High Context: File Tests: Update

✓ schema.org compliant