Sweeper Circuit Breaking
Reference · Applies to Brighter V10
Sweeper Circuit Breaking Overview
Sweeper Circuit Breaking is a resilience feature that prevents failures to publish to one topic from blocking attempts to publish to other topics, when publishing messages from the Outbox. When a topic repeatedly fails to publish, the circuit breaker "trips" that topic, temporarily preventing further publish attempts until a cooldown period expires.
This feature is particularly valuable in scenarios where:
Transport failures: A message broker or queue becomes unavailable
Topic-specific issues: A specific topic/queue has configuration problems or capacity issues
Cascade prevention: Failing topics would otherwise block the Outbox Sweeper from processing healthy topics
Resource protection: Repeated failures to unhealthy topics consume resources without benefit
How Sweeper Circuit Breaking Works
The Sweeper Circuit Breaker operates at the topic level during Outbox clearing operations:
Normal Operation
Outbox Sweeper runs: Periodically attempts to clear outstanding messages from the Outbox
Tripped topics left out: The sweeper asks the Outbox for outstanding messages, passing it the tripped topics to leave out
Publish attempts: The sweeper attempts to publish messages to their respective topics
Success: Messages are published and marked as dispatched
Circuit Breaking Behavior
When a topic fails to publish:
Failure detected: An exception occurs during message publication to a specific topic
Circuit trips: The circuit breaker marks that topic as "tripped"
Cooldown begins: A cooldown counter is set for the tripped topic (default: 10 sweeps)
Subsequent sweeps: Each sweep decrements the counter for every tripped topic before it reads the Outbox, and skips the tripped topics' messages
Recovery: The sweep after the counter reaches zero removes the topic from the tripped list, so a topic sits out
CooldownCountsweepsRetry: That same sweep publishes the topic's messages again
Benefits
Prevents blocking: Healthy topics continue to be processed even when some topics fail
Automatic recovery: Topics automatically recover after the cooldown period
Resource efficiency: Avoids wasting resources on repeated failures to unhealthy topics
Observability: Tripped topics can be monitored and alerted on
Sweeper Circuit Breaking Configuration
Enabling Circuit Breaking
To enable Sweeper Circuit Breaking, register an IAmAnOutboxCircuitBreaker implementation with your IoC container:
Configuration Options
The OutboxCircuitBreakerOptions class provides the following configuration:
CooldownCount
int
10
Sweeper iterations a tripped topic waits before it is retried.
Calculating Cooldown Time
The actual cooldown time depends on how often the Outbox Sweeper runs, which you set with TimerInterval, in seconds, on the options you pass to UseOutboxSweeper. A topic trips during one sweep, sits out the next CooldownCount sweeps, and is retried on the one after:
Formula: Time until retry = (CooldownCount + 1) × TimerInterval
Example:
CooldownCount = 10TimerInterval = 60, so the Sweeper runs every 60 secondsTime until retry = (10 + 1) × 60s = 11 minutes
Sweeper Circuit Breaking Monitoring and Observability
Checking Tripped Topics
You can query the circuit breaker to see which topics are currently tripped:
Logging and Alerts
Set up monitoring to track circuit breaker events:
Sweeper Circuit Breaking Outbox Support
The sweeper does not filter tripped topics itself. It passes TrippedTopics to the Outbox when it asks for outstanding messages, and the Outbox leaves those topics out of its query — so circuit breaking works only where the Outbox honours that list. At Brighter 10.7.0:
With DynamoDB or Spanner, a registered breaker still records trips, and TrippedTopics still reports them, so the monitoring above works. But every sweep reads and sends a tripped topic's messages as though nothing had tripped.
An Outbox that honours the list needs nothing extra: register the breaker and the sweeper beside it as usual. With MongoDB, for example:
Bulk Dispatch Support
With UseBulk set on its options, the sweeper sends each topic's outstanding messages in batches, through a producer that implements IAmABulkMessageProducerAsync. Circuit breaking works as it does for single messages: tripped topics are left out when the sweeper reads the Outbox, and a batch that fails to send trips its topic.
Sweeper Circuit Breaking Best Practices
1. Choose Appropriate Cooldown Periods
Balance between quick recovery and avoiding repeated failures:
Short cooldown (3-5 sweeps): For transient issues, quick recovery desired
Medium cooldown (10-15 sweeps): General purpose, good balance
Long cooldown (20-30 sweeps): For persistent issues, reduce retry overhead
2. Align Cooldown with Sweep Interval
Consider the time until a tripped topic is retried, (CooldownCount + 1) × TimerInterval:
3. Monitor Tripped Topics
Set up monitoring and alerting:
Health checks: Use ASP.NET Core health checks to expose tripped topics
Metrics: Export circuit breaker metrics to Prometheus, DataDog, etc.
Logging: Log when topics trip and recover
Alerts: Alert when topics remain tripped for extended periods
4. Investigate Root Causes
When topics trip repeatedly:
Check broker health: Ensure message broker is operational
Verify permissions: Ensure the application has permissions to publish
Check queue/topic existence: Verify the destination exists
Review capacity: Check if the queue/topic has reached capacity limits
Inspect network: Look for network connectivity issues
5. Use with Outbox Sweeper
Circuit breaking is designed to work with the Outbox Sweeper:
6. Consider Immediate vs. Sweeper Clearing
Only the sweeper skips tripped topics. When you clear explicitly with ClearOutbox or ClearOutboxAsync, Brighter sends every message you name, whether or not its topic is tripped.
A failed send from ClearOutboxAsync does trip the topic, so the sweeper then skips it. A failed send from ClearOutbox trips it only when the producer reports failures through publish confirmation.
7. Test Failure Scenarios
Regularly test circuit breaker behavior:
Simulate broker outages
Test individual topic failures
Verify healthy topics continue processing
Confirm automatic recovery after cooldown
Sweeper Circuit Breaking Troubleshooting
Topics Not Recovering
Problem: Topics remain tripped indefinitely
Solutions:
Verify Outbox Sweeper is running
Check cooldown count is not excessively high
Ensure the Sweeper's
TimerIntervalis appropriateConfirm circuit breaker is properly registered
All Topics Tripping
Problem: All topics become tripped at once
Possible Causes:
Broker is completely down
Network connectivity issues
Authentication/authorization failures
Shared resource exhaustion
Solutions:
Check broker health and connectivity
Verify credentials and permissions
Review broker logs for errors
Consider infrastructure capacity
Messages Stuck in Outbox
Problem: Messages accumulate in Outbox without being dispatched
Check:
Is the Outbox Sweeper enabled?
Are topics currently tripped? Check
TrippedTopicsIs the circuit breaker cooldown too long?
Are there persistent transport issues?
Solutions:
Enable Outbox Sweeper if not already enabled
Investigate why topics are tripping
Reduce cooldown count if appropriate
Fix underlying transport issues
Circuit Breaker Not Working
Problem: Failed topics continue to be retried
Verify:
Circuit breaker is registered:
services.AddSingleton<IAmAnOutboxCircuitBreaker>Using the sweeper:
UseOutboxSweeper()Exceptions are being thrown during publish (not silently failing)
Circuit breaker implementation is correct
Your Outbox leaves tripped topics out — DynamoDB and Spanner do not (see Outbox Support)
Sweeper Circuit Breaking Summary
Sweeper Circuit Breaking provides automatic resilience for Outbox clearing operations by:
Preventing cascade failures when specific topics fail
Automatically recovering after a configurable cooldown period
Allowing healthy topics to continue processing
Protecting resources from repeated failures
Enable circuit breaking by registering IAmAnOutboxCircuitBreaker with your IoC container and configuring appropriate cooldown periods for your application's needs.
Further Reading
Using Sweeper Circuit Breaking - Wiring it up, tuning the cooldown, and custom breakers
Outbox Support - The Outbox and the Sweeper
Distributed Lock - Keeping a single Sweeper active
Last updated
Was this helpful?
