Component Selection Guide#
When to Use What#
Rate Limiting
bucket- API endpoints, bursty trafficleakybucket- Steady processing, smooth ratesconcurrency- Database connections, resource protection
Task Processing
workerpool- Dynamic background tasksscheduler- Time-based, recurring jobspipeline- Multi-stage data processing
Data Processing
stream- Functional operations on datawriter- Async buffered writing
Common Use Cases#
Web API Service
bucketfor API rate limitingconcurrencyfor database connectionsworkerpoolfor background tasks
Data Processing System
streamfor transformationspipelinefor multi-stage workflowswriterfor async output
Job Processing
schedulerfor cron jobsworkerpoolfor dynamic tasksconcurrencyfor resource control
Configuration Examples#
API Rate Limiting
bucket.NewSafe(100, 200) // 100 RPS with burst 200Database Connections
concurrency.NewSafe(20) // Max 20 concurrent connectionsWorker Pool
workerpool.Config{
WorkerCount: 10,
QueueSize: 1000,
TaskTimeout: 30 * time.Second,
}