Workflow

April 30, 2026 ยท View on GitHub

Workflow Logo
Go Reference Mentioned in Awesome Go

Workflow

The type-safe, event-driven workflow orchestration library that scales with your business.

Build robust, distributed workflows in Go with compile-time safety, automatic retries, and horizontal scaling out of the box.

// Define your business logic as type-safe state machines
b := workflow.NewBuilder[Order, OrderStatus]("order-processing")
b.AddStep(OrderCreated, ProcessPayment, PaymentProcessed)
b.AddStep(PaymentProcessed, FulfillOrder, OrderCompleted)

wf := b.Build(kafkaStreamer, sqlStore, roleScheduler)

Why Choose Workflow?

๐ŸŽฏ Type-Safe by Design

Unlike other orchestrators, Workflow leverages Go generics for compile-time guarantees. Catch errors before deployment, not in production.

// Your IDE knows exactly what data flows where
func processPayment(ctx context.Context, r *workflow.Run[Order, OrderStatus]) (OrderStatus, error) {
    // r.Object is typed as *Order, OrderStatus is your enum
    // Compiler catches mismatches before they cause runtime errors
}

โšก Event-Driven Architecture

Built for modern distributed systems. Steps communicate through durable events, enabling:

  • Loose coupling between workflow components
  • Automatic retries with exponential backoff
  • Horizontal scaling across multiple instances
  • Fault tolerance that survives network partitions

๐Ÿ”ง Infrastructure Agnostic

Your choice of database, message queue, and coordination service. Start simple, scale when needed:

// Development: Everything in-memory
wf := b.Build(memstreamer.New(), memrecordstore.New(), memrolescheduler.New())

// Production: Battle-tested infrastructure
wf := b.Build(kafkastreamer.New(), sqlstore.New(), rinkrolescheduler.New())

๐Ÿ“Š Built-in Observability

Production-ready monitoring without the setup overhead:

  • Prometheus metrics for throughput, latency, and error rates
  • Web UI for real-time workflow visualization
  • Structured logging with correlation IDs
  • Distributed tracing support

Perfect For

  • Order Processing: Payment, inventory, fulfillment pipelines
  • User Onboarding: Multi-step verification and activation flows
  • Financial Operations: Transaction processing with compliance checks
  • Data Processing: ETL pipelines with validation and cleanup
  • Approval Workflows: Multi-stakeholder review processes

vs. The Alternatives

FeatureWorkflowTemporalZeebe/Camunda
Type Safetyโœ… Compile-time (Go generics)โŒ Runtime validationโŒ Runtime (BPMN)
Architectureโœ… Event-driven state machinesโš ๏ธ RPC-based activitiesโš ๏ธ Token-based execution
Infrastructureโœ… Your choice (adapters)โŒ Requires Temporal clusterโŒ Requires external engine
Deploymentโœ… Library in your appโŒ Separate server/workersโŒ Separate engine
Learning Curveโœ… Native Go patternsโš ๏ธ New concepts & SDKsโŒ BPMN modeling
Languageโœ… Go-nativeโš ๏ธ Multi-language via gRPCโš ๏ธ Multi-language

Quick Start

go get github.com/luno/workflow
package main

import (
    "context"
    "fmt"
    "github.com/luno/workflow"
    "github.com/luno/workflow/adapters/memstreamer"
    "github.com/luno/workflow/adapters/memrecordstore"
    "github.com/luno/workflow/adapters/memrolescheduler"
)

type TaskStatus int
const (
    TaskStatusUnknown   TaskStatus = 0
    TaskStatusCreated   TaskStatus = 1
    TaskStatusProcessed TaskStatus = 2
    TaskStatusCompleted TaskStatus = 3
)

type Task struct {
    ID   string
    Name string
}

func main() {
    b := workflow.NewBuilder[Task, TaskStatus]("task-processor")

    b.AddStep(TaskStatusCreated, func(ctx context.Context, r *workflow.Run[Task, TaskStatus]) (TaskStatus, error) {
        fmt.Printf("Processing: %s\n", r.Object.Name)
        return TaskStatusProcessed, nil
    }, TaskStatusProcessed)

    b.AddStep(TaskStatusProcessed, func(ctx context.Context, r *workflow.Run[Task, TaskStatus]) (TaskStatus, error) {
        fmt.Printf("Completed: %s\n", r.Object.Name)
        return TaskStatusCompleted, nil
    }, TaskStatusCompleted)

    wf := b.Build(memstreamer.New(), memrecordstore.New(), memrolescheduler.New())

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

    // Trigger a workflow
    runID, _ := wf.Trigger(ctx, "task-1", workflow.WithInitialValue(&Task{
        ID: "task-1",
        Name: "Process Invoice",
    }))

    // Wait for completion
    wf.Await(ctx, "task-1", runID, TaskStatusCompleted)
    fmt.Println("โœ… Workflow completed!")
}

Enterprise Ready

Workflow provides enterprise-grade features:

  • โœ… Exactly-once processing guarantees via transactional outbox pattern
  • โœ… Built-in error handling with pause and retry mechanisms
  • โœ… Comprehensive observability via Prometheus metrics and Web UI
  • โœ… Horizontal scaling through role-based scheduling
  • โœ… Infrastructure flexibility via pluggable adapters
  • โœ… Production deployment patterns for various scales

Documentation

TopicDescription
Getting StartedInstall and build your first workflow
Core ConceptsUnderstand Runs, Events, and State Machines
ArchitectureDeep dive into system design and components
StepsBuild workflow logic with step functions
AdaptersInfrastructure integration guide
Database SetupComplete MariaDB/MySQL & PostgreSQL setup guide
CallbacksHandle external events and webhooks
TimeoutsAdd time-based operations
ConnectorsIntegrate with external event streams
HooksReact to workflow lifecycle changes
ConfigurationTune performance and behaviour
MonitoringObservability and debugging

Examples & Tutorials

ExampleDescription
Getting StartedYour first workflow in 5 minutes
SQL ExampleComplete MariaDB/MySQL integration with Docker
Order ProcessingComplex e-commerce workflow with payments & fulfilment
CallbacksHandle external webhooks and events
TimeoutsSchedule and timeout operations
ConnectorsIntegrate with external event streams

Community & Support

  • ๐Ÿ“š Documentation - Comprehensive guides and examples
  • ๐Ÿ› Issues - Bug reports and feature requests
  • ๐Ÿ’ฌ Discussions - Community Q&A

Installation

go get github.com/luno/workflow

# Production adapters (install as needed)
go get github.com/luno/workflow/adapters/kafkastreamer
go get github.com/luno/workflow/adapters/sqlstore
go get github.com/luno/workflow/adapters/rinkrolescheduler
go get github.com/luno/workflow/adapters/webui

License

MIT License


Ready to build reliable workflows? Get started in 5 minutes โ†’