# richardknop/machinery architecture

> Architecture diagram of the GitHub repository richardknop/machinery, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/richardknop/machinery
- Repository: https://github.com/richardknop/machinery

## Overview

Machinery is a distributed asynchronous task queue. A producer submits task signatures or workflows to a server, which publishes them through a broker; workers consume messages, execute registered tasks, and persist task state and results through a backend. The repository contains recommended, dependency-injected v2 and legacy v1 implementations. The graph preserves their major runtime components and documented broker/backend choices; several adapter relationships are shown only where the excerpts or README establish them, so unsampled wiring is omitted.

Main entry points: [`v2/server.go`](https://github.com/richardknop/machinery/blob/master/v2/server.go) (Server v2), [`v1/server.go`](https://github.com/richardknop/machinery/blob/master/v1/server.go) (Server v1), [`v2/worker.go`](https://github.com/richardknop/machinery/blob/master/v2/worker.go) (Worker v2), [`v1/worker.go`](https://github.com/richardknop/machinery/blob/master/v1/worker.go) (Worker v1)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Task API"]
  node_v2server["Server v2<br/>[server.go]"]
  node_v1server["Server v1<br/>[server.go]"]
  node_v2tasks["Task Definitions v2"]
  node_v1tasks["Task Definitions v1"]
  node_v2workflows["Workflows v2<br/>[server.go]"]
  node_v1workflows["Workflows v1<br/>[server.go]"]
  node_v2results["Async Results v2<br/>[async_result.go]"]
  node_v1results["Async Results v1<br/>[async_result.go]"]
end

subgraph group_execution["Worker Execution"]
  node_v2worker["Worker v2<br/>[worker.go]"]
  node_v1worker["Worker v1<br/>[worker.go]"]
  node_v2retry["Retry Policy v2<br/>[retry.go]"]
  node_v1retry["Retry Policy v1<br/>[retry.go]"]
end

subgraph group_messaging["Messaging"]
  node_v2broker["Broker Adapters v2"]
  node_v1broker["Broker Adapters v1"]
  node_amqp["AMQP Broker v2<br/>[amqp.go]"]
end

subgraph group_state["State and Coordination"]
  node_v2backend["Backend Adapters v2"]
  node_v1backend["Backend Adapters v1"]
  node_v2dynamo["DynamoDB Backend v2<br/>[dynamodb.go]"]
  node_v1dynamo["DynamoDB Backend v1<br/>[dynamodb.go]"]
  node_v2lock["Lock Adapters v2"]
  node_v1lock["Lock Adapters v1"]
end

subgraph group_crosscut["Configuration and Observability"]
  node_config["Configuration"]
  node_tracing["Tracing v2<br/>[tracing.go]"]
  node_v1tracing["Tracing v1<br/>[tracing.go]"]
end

node_producer(("Task Producer"))
node_queue["Message Broker"]
node_resultstore[("Result Store")]

node_producer -->|"submits tasks"| node_v2server
node_producer -->|"submits tasks"| node_v1server
node_v2server -.->|"publishes messages"| node_v2broker
node_v1server -.->|"publishes messages"| node_v1broker
node_v2server -->|"returns handles"| node_v2results
node_v1server -->|"returns handles"| node_v1results
node_v2server -->|"dispatches workflows"| node_v2workflows
node_v1server -->|"dispatches workflows"| node_v1workflows
node_v2server -->|"accepts signatures"| node_v2tasks
node_v1server -->|"accepts signatures"| node_v1tasks
node_v2worker -->|"consumes messages"| node_v2broker
node_v1worker -->|"consumes messages"| node_v1broker
node_v2broker -.->|"transfers messages"| node_queue
node_v1broker -.->|"transfers messages"| node_queue
node_v2worker -->|"processes tasks"| node_v2tasks
node_v1worker -->|"processes tasks"| node_v1tasks
node_v2worker -->|"applies retry"| node_v2retry
node_v1worker -->|"applies retry"| node_v1retry
node_v2worker -.->|"updates task state"| node_v2backend
node_v1worker -.->|"updates task state"| node_v1backend
node_v2worker -->|"resubmits retries"| node_v2server
node_v1worker -->|"resubmits retries"| node_v1server
node_v2worker -->|"sends chord callback"| node_v2server
node_v1worker -->|"sends chord callback"| node_v1server
node_v2backend -.->|"backs result handles"| node_v2results
node_v1backend -.->|"backs result handles"| node_v1results
node_v2dynamo -.->|"persists state"| node_resultstore
node_v1dynamo -.->|"persists state"| node_resultstore
node_v2server -->|"coordinates schedules"| node_v2lock
node_v1server -->|"coordinates schedules"| node_v1lock
node_v2server -->|"uses configuration"| node_config
node_v1server -.->|"uses configuration"| node_config
node_v2server -->|"injects trace context"| node_tracing
node_v2worker -->|"extracts trace context"| node_tracing
node_v1server -->|"injects trace context"| node_v1tracing
node_v1worker -->|"extracts trace context"| node_v1tracing
node_amqp -->|"publishes and consumes"| node_queue
node_v2server -.->|"publishes messages"| node_amqp

click node_v2server "https://github.com/richardknop/machinery/blob/master/v2/server.go"
click node_v1server "https://github.com/richardknop/machinery/blob/master/v1/server.go"
click node_v2tasks "https://github.com/richardknop/machinery/tree/master/v2/tasks"
click node_v1tasks "https://github.com/richardknop/machinery/tree/master/v1/tasks"
click node_v2workflows "https://github.com/richardknop/machinery/blob/master/v2/server.go"
click node_v1workflows "https://github.com/richardknop/machinery/blob/master/v1/server.go"
click node_v2results "https://github.com/richardknop/machinery/blob/master/v2/backends/result/async_result.go"
click node_v1results "https://github.com/richardknop/machinery/blob/master/v1/backends/result/async_result.go"
click node_v2worker "https://github.com/richardknop/machinery/blob/master/v2/worker.go"
click node_v1worker "https://github.com/richardknop/machinery/blob/master/v1/worker.go"
click node_v2retry "https://github.com/richardknop/machinery/blob/master/v2/retry/retry.go"
click node_v1retry "https://github.com/richardknop/machinery/blob/master/v1/retry/retry.go"
click node_v2broker "https://github.com/richardknop/machinery/tree/master/v2/brokers"
click node_v1broker "https://github.com/richardknop/machinery/tree/master/v1/brokers"
click node_amqp "https://github.com/richardknop/machinery/blob/master/v2/brokers/amqp/amqp.go"
click node_v2backend "https://github.com/richardknop/machinery/tree/master/v2/backends"
click node_v1backend "https://github.com/richardknop/machinery/tree/master/v1/backends"
click node_v2dynamo "https://github.com/richardknop/machinery/blob/master/v2/backends/dynamodb/dynamodb.go"
click node_v1dynamo "https://github.com/richardknop/machinery/blob/master/v1/backends/dynamodb/dynamodb.go"
click node_v2lock "https://github.com/richardknop/machinery/tree/master/v2/locks"
click node_v1lock "https://github.com/richardknop/machinery/tree/master/v1/locks"
click node_config "https://github.com/richardknop/machinery/tree/master/v2/config"
click node_tracing "https://github.com/richardknop/machinery/blob/master/v2/tracing/tracing.go"
click node_v1tracing "https://github.com/richardknop/machinery/blob/master/v1/tracing/tracing.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_v2server,node_v1server,node_v2tasks,node_v1tasks,node_v2workflows,node_v1workflows,node_v2results,node_v1results toneBlue
class node_v2worker,node_v1worker,node_v2retry,node_v1retry,node_resultstore toneAmber
class node_v2broker,node_v1broker,node_amqp toneMint
class node_v2backend,node_v1backend,node_v2dynamo,node_v1dynamo,node_v2lock,node_v1lock,node_producer toneRose
class node_config,node_tracing,node_v1tracing,node_queue toneIndigo
```

## Components

### Task API

- [Server v2](https://github.com/richardknop/machinery/blob/master/v2/server.go): `v2/server.go`
- [Server v1](https://github.com/richardknop/machinery/blob/master/v1/server.go): `v1/server.go`
- [Task Definitions v2](https://github.com/richardknop/machinery/tree/master/v2/tasks): `v2/tasks`
- [Task Definitions v1](https://github.com/richardknop/machinery/tree/master/v1/tasks): `v1/tasks`
- [Workflows v2](https://github.com/richardknop/machinery/blob/master/v2/server.go): `v2/server.go`
- [Workflows v1](https://github.com/richardknop/machinery/blob/master/v1/server.go): `v1/server.go`
- [Async Results v2](https://github.com/richardknop/machinery/blob/master/v2/backends/result/async_result.go): `v2/backends/result/async_result.go`
- [Async Results v1](https://github.com/richardknop/machinery/blob/master/v1/backends/result/async_result.go): `v1/backends/result/async_result.go`

### Worker Execution

- [Worker v2](https://github.com/richardknop/machinery/blob/master/v2/worker.go): `v2/worker.go`
- [Worker v1](https://github.com/richardknop/machinery/blob/master/v1/worker.go): `v1/worker.go`
- [Retry Policy v2](https://github.com/richardknop/machinery/blob/master/v2/retry/retry.go): `v2/retry/retry.go`
- [Retry Policy v1](https://github.com/richardknop/machinery/blob/master/v1/retry/retry.go): `v1/retry/retry.go`

### Messaging

- [Broker Adapters v2](https://github.com/richardknop/machinery/tree/master/v2/brokers): `v2/brokers`
- [Broker Adapters v1](https://github.com/richardknop/machinery/tree/master/v1/brokers): `v1/brokers`
- [AMQP Broker v2](https://github.com/richardknop/machinery/blob/master/v2/brokers/amqp/amqp.go): `v2/brokers/amqp/amqp.go`

### State and Coordination

- [Backend Adapters v2](https://github.com/richardknop/machinery/tree/master/v2/backends): `v2/backends`
- [Backend Adapters v1](https://github.com/richardknop/machinery/tree/master/v1/backends): `v1/backends`
- [DynamoDB Backend v2](https://github.com/richardknop/machinery/blob/master/v2/backends/dynamodb/dynamodb.go): `v2/backends/dynamodb/dynamodb.go`
- [DynamoDB Backend v1](https://github.com/richardknop/machinery/blob/master/v1/backends/dynamodb/dynamodb.go): `v1/backends/dynamodb/dynamodb.go`
- [Lock Adapters v2](https://github.com/richardknop/machinery/tree/master/v2/locks): `v2/locks`
- [Lock Adapters v1](https://github.com/richardknop/machinery/tree/master/v1/locks): `v1/locks`

### Configuration and Observability

- [Configuration](https://github.com/richardknop/machinery/tree/master/v2/config): `v2/config`
- [Tracing v2](https://github.com/richardknop/machinery/blob/master/v2/tracing/tracing.go): `v2/tracing/tracing.go`
- [Tracing v1](https://github.com/richardknop/machinery/blob/master/v1/tracing/tracing.go): `v1/tracing/tracing.go`

### Other components

- **Task Producer**
- **Message Broker**
- **Result Store**

## Connections

- Task Producer → Server v2: submits tasks
- Task Producer → Server v1: submits tasks
- Server v2 → Broker Adapters v2: publishes messages (evidence: `v2/server.go`)
- Server v1 → Broker Adapters v1: publishes messages (evidence: `v1/server.go`)
- Server v2 → Async Results v2: returns handles (evidence: `v2/server.go`)
- Server v1 → Async Results v1: returns handles (evidence: `v1/server.go`)
- Server v2 → Workflows v2: dispatches workflows (evidence: `v2/server.go`)
- Server v1 → Workflows v1: dispatches workflows (evidence: `v1/server.go`)
- Server v2 → Task Definitions v2: accepts signatures (evidence: `v2/server.go`)
- Server v1 → Task Definitions v1: accepts signatures (evidence: `v1/server.go`)
- Worker v2 → Broker Adapters v2: consumes messages (evidence: `v2/worker.go`)
- Worker v1 → Broker Adapters v1: consumes messages (evidence: `v1/worker.go`)
- Broker Adapters v2 → Message Broker: transfers messages
- Broker Adapters v1 → Message Broker: transfers messages
- Worker v2 → Task Definitions v2: processes tasks (evidence: `v2/worker.go`)
- Worker v1 → Task Definitions v1: processes tasks (evidence: `v1/worker.go`)
- Worker v2 → Retry Policy v2: applies retry (evidence: `v2/worker.go`)
- Worker v1 → Retry Policy v1: applies retry (evidence: `v1/worker.go`)
- Worker v2 → Backend Adapters v2: updates task state (evidence: `v2/worker.go`)
- Worker v1 → Backend Adapters v1: updates task state (evidence: `v1/worker.go`)
- Worker v2 → Server v2: resubmits retries (evidence: `v2/worker.go`)
- Worker v1 → Server v1: resubmits retries (evidence: `v1/worker.go`)
- Worker v2 → Server v2: sends chord callback (evidence: `v2/worker.go`)
- Worker v1 → Server v1: sends chord callback (evidence: `v1/worker.go`)
- Backend Adapters v2 → Async Results v2: backs result handles
- Backend Adapters v1 → Async Results v1: backs result handles
- DynamoDB Backend v2 → Result Store: persists state
- DynamoDB Backend v1 → Result Store: persists state
- Server v2 → Lock Adapters v2: coordinates schedules (evidence: `v2/server.go`)
- Server v1 → Lock Adapters v1: coordinates schedules (evidence: `v1/server.go`)
- Server v2 → Configuration: uses configuration (evidence: `v2/server.go`)
- Server v1 → Configuration: uses configuration
- Server v2 → Tracing v2: injects trace context (evidence: `v2/server.go`)
- Worker v2 → Tracing v2: extracts trace context (evidence: `v2/worker.go`)
- Server v1 → Tracing v1: injects trace context (evidence: `v1/server.go`)
- Worker v1 → Tracing v1: extracts trace context (evidence: `v1/worker.go`)
- AMQP Broker v2 → Message Broker: publishes and consumes (evidence: `v2/brokers/amqp/amqp.go`)
- Server v2 → AMQP Broker v2: publishes messages
