Smoother is a Go package that provides traffic smoothing capabilities by introducing controlled delays to maintain a target request rate. Unlike traditional rate limiters that reject excess requests, Smoother keeps all requests active while ensuring a consistent throughput through intelligent request spacing.
- 🎯 Maintains target RPS through controlled delays rather than request rejection
- ⏱️ Dynamically adjusts wait times to smooth traffic spikes
- 🔄 Keeps all requests active and processing
- 🌊 Smooths out traffic spikes while ensuring all requests complete
- 📡 Supports both local and distributed (Redis-based) implementations
- 🛠️ Pluggable interface for custom implementations
- 🔌 Thread-safe operation
- 🚦 Throttler package for back pressure pattern
- No dropped connections or rejected requests
- Consistent, predictable throughput
- Better resource utilization through traffic smoothing
- Ideal for scenarios where request completion is more important than immediate error response
- Suitable for both single-instance and distributed systems
Special features of the implementation Primary + fallback + circuit breaker
In the FallbackTryer, requests are sent concurrently to both the primary and fallback. When in the closed state, it chooses the primary if it succeeds, and falls back if it fails. Consequently, both implementations handle traffic simultaneously. Traffic is only removed from the primary when the circuit breaker opens
go get github.com/n-r-w/smoother
- Redis Rate
- Throttled with Redis backend
- In-memory
- Primary + fallback + circuit breaker. For example, to use Redis Rate as the primary Tryer and In-memory as the fallback.
See the example for usage examples.
The throttler package provides a simple implementation of the back pressure pattern.