Queues are the backbone of modern Laravel applications. They handle payments, notifications, emails, and background jobs that keep SaaS platforms running smoothly. But what happens when an external service — Stripe, Twilio, SendGrid — goes down?
Without protection, your queue can collapse under the weight of retries and timeouts. That’s where Laravel Fuse comes in. Fuse introduces the circuit breaker pattern to Laravel queues, intelligently halting jobs when services fail, and resuming them when recovery is detected.
This blog explores why Fuse matters, how it works, and how to implement it with real-world examples.
⚡ The Problem: Cascading Failures in Queues
Imagine this scenario:
- Your app has 10,000 jobs queued to charge customers via Stripe.
- Stripe goes down at midnight.
- Each job waits 30 seconds for a timeout.
- Jobs retry multiple times.
- The queue freezes for hours, blocking unrelated jobs like emails or notifications.
This is a cascading failure — one service outage cripples your entire system.
🔧 The Solution: Circuit Breakers
The circuit breaker pattern comes from electrical engineering. When a circuit overloads, the breaker “opens” to stop damage. Once conditions normalize, the breaker “closes” again.
Applied to software:
- Closed state: Jobs run normally.
- Open state: After repeated failures, jobs are skipped or delayed.
- Half-open state: Fuse tests the service with a few jobs. If successful, the circuit closes.
This prevents queues from collapsing during outages.
🛠️ What Is Laravel Fuse?
Laravel Fuse is a package that brings circuit breakers to Laravel queues. It tracks failures per service, opens circuits when thresholds are exceeded, and closes them automatically when recovery is detected.
Key features:
- Job-level protection.
- Service-aware tracking (e.g., Stripe, Twilio).
- Configurable thresholds and timeouts.
- Automatic recovery.
- Minimal setup.
📚 Installation & Setup
Install via Composer:
composer require harris21/laravel-fuse
Publish config:
php artisan vendor:publish --tag=fuse-config
🧩 Example: Protecting Stripe Jobs
use Fuse;
class ChargeCustomerJob implements ShouldQueue
{
public function handle()
{
if (Fuse::for('stripe')->isOpen()) {
return; // Skip or delay
}
try {
Stripe::charge($this->customer);
} catch (\Exception $e) {
Fuse::for('stripe')->recordFailure();
throw $e;
}
Fuse::for('stripe')->recordSuccess();
}
}
Configuration:
Fuse::for('stripe')
->threshold(5) // Open after 5 failures
->timeout(300); // Stay open for 5 minutes
🧪 Real-World Scenarios
1. Stripe Outage
- Without Fuse: Queue freezes for 25+ hours.
- With Fuse: Circuit opens after 5 failures, jobs skip, queue clears in seconds.
2. Twilio SMS Failures
- Twilio API rate-limits requests.
- Fuse detects repeated failures, opens circuit, delays jobs.
- Once Twilio recovers, Fuse closes circuit automatically.
3. SendGrid Email Downtime
- Thousands of emails queued.
- Fuse prevents retries from overwhelming SendGrid.
- Queue remains healthy, other jobs continue.
🔍 Advanced Usage
Service-Specific Circuits
Fuse::for('twilio')->threshold(3)->timeout(120);
Fuse::for('sendgrid')->threshold(10)->timeout(600);
Monitoring Fuse Status
You can log Fuse state changes:
Fuse::for('stripe')->onOpen(function () {
Log::warning('Stripe circuit opened!');
});
Half-Open State Testing
Fuse can test recovery with a few jobs:
Fuse::for('stripe')->halfOpenAfter(300); // Test after 5 minutes
🛡️ Benefits of Laravel Fuse
- Resilience: Prevents cascading failures.
- Efficiency: Saves queue workers from wasted retries.
- Clarity: Logs make outages visible.
- Automation: Circuits close automatically on recovery.
- Flexibility: Configure thresholds per service.
⚠️ Pitfalls & Fixes
| Pitfall | Fix |
|---|---|
| Circuit opens too quickly | Increase threshold |
| Circuit stays open too long | Adjust timeout |
| Jobs skipped silently | Add logging or alerts |
| Overlapping services | Use service-specific circuits |
| Misconfigured thresholds | Test in staging before production |
🔮 The Future of Fuse
Fuse is evolving with:
- Dashboard integration: Visualize circuit states.
- Notifications: Slack/email alerts when circuits open.
- Adaptive thresholds: AI-driven failure detection.
- Integration with Laravel Horizon: Monitor Fuse alongside queues.
📚 Example: SaaS CRM with Fuse
A CRM app sends invoices via Stripe, SMS via Twilio, and emails via SendGrid.
- Stripe outage → Fuse opens, invoices delayed.
- Twilio rate-limit → Fuse opens, SMS jobs paused.
- SendGrid downtime → Fuse opens, emails skipped.
Meanwhile, unrelated jobs (like analytics or logging) continue without disruption. Fuse isolates failures, keeping the system healthy.
Final Thoughts
Laravel Fuse brings resilience to Laravel queues. By implementing circuit breakers, you protect your app from cascading failures, preserve queue health, and improve reliability.
In SaaS apps where external APIs are single points of failure, Fuse is a must-have tool. It’s simple, powerful, and aligns perfectly with Laravel’s philosophy of developer happiness.
