Stage 3 · Build
Long-Running Daemons & Services
Background Workers
errgroup, bounded queues, backoff, jitter, and draining worker pools safely.
Worker Patterns
Background workers process tasks asynchronously. They are essential for retrying failed operations, batch processing, and scheduled work. Choose the right pattern based on your needs.
| Pattern | Use Case | Complexity |
|---|---|---|
| errgroup | Parallel tasks with error handling | Low |
| Worker pool | Fixed concurrency with job queue | Medium |
| Semaphore | Dynamic concurrency limiting | Low |
| Pipeline | Multi-stage processing | High |
errgroup Workers
Bounded Queues
Backoff and Jitter
Safe Draining
Error Handling Strategies
Track queue length, worker count, processing time, and error rate. Alert on growing queue length — it indicates workers cannot keep up. Monitor error rates to detect upstream failures.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.