Workflow
lunarforge/workflow MIT License Mentioned in Awesome Go

Workflow

Type-safe workflow orchestration for Go. Event-driven state machines with pluggable infrastructure.

Stop gluing services together with ad-hoc retry loops and home-grown state machines. Workflow gives you a production-grade primitive for multi-step processes that are reliable, observable, and maintainable — backed by Go generics for full compile-time safety.

Capabilities

Everything you need in production

Type-Safe State Machines

Built on Go generics — Workflow[Type, Status]. Compile-time guarantees on status transitions mean no runtime surprises and full IDE support across your entire workflow definition.

Pluggable Infrastructure

Swap databases and message queues without changing workflow logic. Adapters for Kafka, PostgreSQL, MySQL, Redis, NATS, and in-memory implementations for local development.

Exactly-Once Processing

Transactional outbox pattern with record versioning ensures events are never lost or duplicated. Your workflow steps execute exactly once, even across restarts and failures.

Horizontal Scaling

Role-based scheduling with sharded parallel consumers. Scale throughput by adding instances — no coordination overhead or single points of failure.

Rich Lifecycle Control

Pause, Resume, Cancel, and Retry any workflow run. GDPR-compliant DeleteData support built in, so you can handle data erasure requests without custom plumbing.

Built-in Observability

Prometheus metrics, structured logging, W3C distributed tracing, and auto-generated Mermaid state diagrams. Full visibility from day one — no instrumentation required.

Architecture

How it works

Workflow models your domain as an event-driven state machine. Each step listens on a stream, processes a record transactionally, and advances its status. The pluggable layer means you choose the infrastructure — Workflow handles the rest.

Workflow architecture diagram

State Transitions

Auto-generated state diagrams

Workflow auto-generates Mermaid state diagrams from your workflow definition. Every possible transition is documented without any extra effort — always in sync with the code.

Workflow state diagram

Example

Clean by design

No YAML. No DSL. Just Go. Define your domain types, wire up your steps, and hand off infrastructure at build time. The generics keep every status transition compile-time safe.

// Define your domain types
type Order struct { ID string; Total float64 }
type Status int
const (
    Created         Status = iota
    PaymentProcessed
    Fulfilled
)

// Build the workflow
b := workflow.NewBuilder[Order, Status]("orders")
b.AddStep(Created, processPayment, PaymentProcessed)
b.AddStep(PaymentProcessed, fulfillOrder, Fulfilled)

wf := b.Build(
    kafkastreamer.New(brokers),
    sqlstore.New(db),
    rinkrolescheduler.New(client),
)

// Run and trigger
ctx := context.Background()
wf.Run(ctx)
defer wf.Stop()

runID, _ := wf.Trigger(ctx, "order-123",
    workflow.WithInitialValue(&Order{ID: "123", Total: 99.99}),
)

Integrations

Bring your own infrastructure

First-party adapters for the most common stacks. Swap any layer without touching your workflow logic.

Event Streaming

KafkaNATSReflexIn-Memory

Persistence

PostgreSQLMySQLRedisIn-Memory

Coordination

Rink (consensus)In-Memory

Monitoring

FlowWatch Web UIPrometheusW3C Tracing

Open source

Try Workflow

Workflow is MIT licensed, production-grade, and actively maintained. Star it on GitHub or reach out to talk about your use case.