Circuit Breaker Architecture
Overview
Tasker implements circuit breaker functionality through its distributed, SQL-driven retry architecture rather than through traditional in-memory circuit breaker objects. This approach provides better durability, observability, and coordination across multiple worker processes.
Why Circuit Breaker Patterns Matter
Circuit breakers prevent cascading failures by:
Failing fast when services are unavailable
Backing off to reduce load on failing services
Automatically recovering when services become healthy
Providing observability into failure patterns
How Tasker Implements Circuit Breaker Logic
1. Fail-Fast Through Step State Management
# Tasker automatically fails fast through step state transitions
step.current_state # 'pending' β 'in_progress' β 'complete' | 'error'
# Failed steps are immediately marked as 'error' state
# No further processing attempts until retry conditions are met2. Intelligent Backoff (The "Open Circuit" State)
Benefits over traditional circuit breakers:
Persistent across restarts - State stored in database, not memory
Distributed coordination - Multiple workers respect the same backoff timing
Configurable per step - Different services can have different backoff strategies
Observable through SQL - Easy to query and monitor backoff states
3. Automatic Recovery (The "Half-Open" State)
4. Error Classification with RetryableError vs PermanentError
Comparison: Traditional vs Tasker Circuit Breaker
State Storage
In-memory (volatile)
Database (persistent)
Coordination
Per-process
Distributed across workers
Observability
Custom metrics
SQL queries + structured logging
Recovery
Time-based
Intelligent backoff + dependency-aware
Configuration
Global per service
Per-step + per-task customization
Failure Classification
Binary (fail/success)
Typed errors (RetryableError, PermanentError)
Key Components
1. SQL Functions for Circuit Logic
get_step_readiness_status()- Determines if steps are ready for executionBackoff calculation - Exponential backoff with jitter and caps
Dependency resolution - Ensures proper execution order
2. Orchestration Components
3. Error Handling Hierarchy
Circuit States in Tasker Terms
Closed (healthy)
ready_for_execution = true
No recent failures, dependencies satisfied
Open (failing fast)
retry_eligible = false
Within backoff period or max retries exceeded
Half-Open (testing)
retry_eligible = true
Backoff period expired, ready for retry attempt
Monitoring and Observability
SQL Queries for Circuit State
Structured Logging Events
Best Practices
1. Use Typed Errors in API Handlers
2. Configure Appropriate Retry Limits
3. Monitor Circuit Health
Why This Architecture is Superior
Durability - Circuit state survives process restarts and deployments
Distributed Coordination - Multiple workers coordinate through database state
Granular Control - Different APIs can have different backoff strategies
Built-in Observability - Rich SQL queries and structured logging
Dependency Awareness - Circuit decisions consider workflow dependencies
Type Safety - Explicit error classification prevents retry of permanent failures
Conclusion
Tasker's architecture already implements sophisticated circuit breaker patterns through its SQL-driven, distributed retry system. This approach provides better durability, observability, and coordination than traditional in-memory circuit breakers, while maintaining the same core benefits of failing fast, backing off intelligently, and recovering automatically.
The key insight is that persistence + distributed coordination > in-memory circuit objects for workflow orchestration systems.
Real-World Example
For a practical demonstration of these patterns in action, see Chapter 3: Microservices Coordination, which shows how to apply Tasker's circuit breaker architecture to coordinate user registration across multiple services.
Last updated