Dispatch your jobs
Background jobs, durable workflows, cron scheduling, and distributed workers — out of the box.
go get github.com/xraph/dispatchEverything you need for background processing
Dispatch handles the hard parts — retries, scheduling, dead letters, worker coordination — so you can focus on your business logic.
Background Jobs
Define typed handlers, enqueue with priority, and retry with configurable backoff. No event is lost, ever.
dispatch.Register("email.send", dispatch.WithHandler(sendEmail), dispatch.WithPriority(High), dispatch.WithRetry(5),)Durable Workflows
Multi-step Go functions that checkpoint progress and resume after failure. No YAML, no DSL.
dispatch.Workflow("onboard.user", dispatch.Step("validate", validateUser), dispatch.Step("provision", provisionAccount), dispatch.Step("notify", notifyUser),)Dead Letter Queue
Jobs that exhaust retries are captured automatically. Inspect, debug, and replay them on demand.
items, _ := d.DLQ().List(ctx, dlq.WithJobType("email.send"), dlq.WithLimit(10),)d.DLQ().Replay(ctx, items[0].ID)Distributed Cron
Leader-elected cron scheduling with per-tenant support and runtime enable/disable.
dispatch.Cron("daily.report", dispatch.WithSchedule("0 9 * * *"), dispatch.WithLeaderElection(true), dispatch.WithTenant(tenantID),)Distributed Workers
Worker registration, heartbeats, leader election, and automatic work stealing across nodes.
d.Workers().Register(ctx, dispatch.Worker{ ID: workerID, Capacity: 10, Heartbeat: 30 * time.Second,})Pluggable Stores
Ship with in-memory for dev, swap to PostgreSQL for production. Bring your own store with a simple interface.
d, _ := dispatch.New( dispatch.WithStore(postgres.New(db)), dispatch.WithWorkers(8), dispatch.WithLogger(slog.Default()),)From enqueue to execution. Automatically.
Dispatch orchestrates the entire job lifecycle — scheduling, execution, retries, and dead-letter routing.
Type-Safe Jobs
Every job is typed and validated before execution. Mismatched payloads fail at compile time, not runtime.
Priority Scheduling
Jobs are scheduled by priority and distributed to available workers. Each worker has independent capacity and backoff policies.
Outcome Routing
Success = completed. Transient error = retry with backoff. Exhausted retries = dead letter queue for inspection and replay.
Simple API. Production power.
Enqueue your first job in under 20 lines. Handle typed payloads on the worker side with zero boilerplate.
1package main2 3import (4 "log/slog"5 "github.com/xraph/dispatch"6 "github.com/xraph/dispatch/store/memory"7)8 9func main() {10 d, _ := dispatch.New(11 dispatch.WithStore(memory.New()),12 dispatch.WithWorkers(4),13 dispatch.WithLogger(slog.Default()),14 )15 16 "text-fd-muted-foreground/60 italic">// Register a typed job handler17 dispatch.Register(d, "email.send", sendEmail)18 19 "text-fd-muted-foreground/60 italic">// Enqueue a job with options20 d.Enqueue(ctx, dispatch.Job{21 Type: "email.send",22 Payload: emailJSON,23 Priority: dispatch.High,24 })25}1package main2 3import (4 "context"5 "github.com/xraph/dispatch"6)7 8type EmailInput struct {9 To string `json:"to"`10 Subject string `json:"subject"`11 Body string `json:"body"`12}13 14func sendEmail(15 ctx context.Context,16 job *dispatch.Job[EmailInput],17) error {18 input := job.Payload19 20 if err := mailer.Send(21 input.To, input.Subject, input.Body,22 ); err != nil {23 "text-fd-muted-foreground/60 italic">// Mark transient errors as retryable24 return dispatch.Retryable(err)25 }26 return nil27}Start dispatching jobs
Add production-grade background processing to your Go service in minutes. Dispatch handles scheduling, retries, dead letters, and worker coordination out of the box.
go get github.com/xraph/dispatch