Queues
GoFlow provides distributed job queues for async processing.
Basic Usage
This creates a connection to DragonflyDB (or Redis), creates a typed job, and adds it to the queue. Jobs are persisted until a worker picks them up.
Worker
Workers are long-running processes that pull jobs from the queue and execute them. The concurrency parameter (10 here) controls how many jobs run in parallel. Return an error to trigger a retry.
Job Options
Job options let you customize processing behavior:
- Priority - High-priority jobs jump ahead in the queue
- MaxRetries - Automatic retry on failure with backoff
- Metadata - Attach tracking info for debugging
Queue Sharding
Scale horizontally with sharded queues:
Sharding distributes jobs across multiple Redis instances. This prevents any single instance from becoming a bottleneck. The strategy determines how jobs are assigned:
- HashShard - Consistent hashing on job ID (same job always goes to same shard)
- RoundRobinShard - Even distribution across shards
- LeastLoadedShard - Route to the shard with fewest pending jobs
Distributed Locking
Prevent duplicate job processing:
In distributed systems, multiple workers might try to process the same job. Distributed locks ensure only one worker succeeds. The TTL (30s here) auto-releases the lock if the worker crashes.
Dead Letter Queue
Handle permanently failed jobs:
Jobs that fail after max retries go to the Dead Letter Queue instead of being lost. You can inspect them, fix the issue, and retry. Alerters notify your team immediately when jobs fail permanently.
Event Sourcing
Track all job events:
Event sourcing provides a complete audit log of every job's lifecycle. You can see exactly what happened, when, and debug issues even after the fact. The subscription feature enables real-time dashboards.
Webhook Integration
Trigger jobs from external webhooks:
This creates an HTTP endpoint that external services can call. When Stripe sends an event to /webhooks/stripe, it automatically becomes a handle_stripe_event job in your queue.
Metrics
Metrics are essential for production monitoring. GoFlow provides Prometheus-compatible metrics for queue depth, job duration, success/failure rates, and more. Connect to Grafana for beautiful dashboards.
Delayed Jobs
Delayed jobs let you schedule work for the future. Common uses include reminder emails, subscription renewals, or any time-based business logic. The scheduler checks periodically and enqueues jobs when their time comes.
