Architecture
The orchestrator is a single Rust service. Agents and apps call it over one of several protocols; it maps every protocol onto one cart and checkout model, runs that model through a deterministic state machine, and calls your existing backends over plain HTTP.
This page explains how the pieces fit together. For the HTTP surface see the consumption guide; for the calls it makes to your backends see the provider API.
Crates
The workspace is split so that the domain model has no I/O, the runtime has no HTTP, and every protocol shim sits at the edge.
flowchart TB
http["orchestrator-http<br/>axum server, routes, auth,<br/>RFC 9421 signing, MPP 402"]
mcp["orchestrator-mcp<br/>MCP JSON-RPC tool server"]
api["orchestrator-api<br/>facade, authz, AP2 checks,<br/>UCP and ACP mapping, signing keys"]
runtime["orchestrator-runtime<br/>runner, idempotency, outbox,<br/>dead-letter, inbox, persistence"]
core["orchestrator-core<br/>domain types, state machines,<br/>policy, validation"]
contracts["provider-contracts<br/>provider traits"]
adapters["integration-adapters<br/>HTTP clients for your backends"]
mocks["provider-mocks<br/>in-memory providers for dev and tests"]
obs["orchestrator-observability<br/>tracing, Prometheus metrics"]
http --> mcp
http --> api
mcp --> api
api --> runtime
runtime --> core
runtime --> contracts
contracts --> core
adapters --> contracts
mocks --> contracts
http --> adapters
http --> mocks
http -.-> obs
runtime -.-> obs
adapters -.-> obs
| Crate | Role |
|---|---|
orchestrator-core | Domain types (CartProjection, CheckoutRequest, TransactionResult), the cart and checkout state machines, the policy engine (maximum totals, blocked geographies, payment constraints) and request validation. Pure logic, no I/O. |
provider-contracts | The traits a backend implements: CatalogProvider, PricingProvider, TaxProvider, GeoProvider, PaymentProvider, ReceiptProvider, plus optional fulfillment, payment delegation and identity linking. |
integration-adapters | HTTP implementations of those traits. Shared client with timeouts, retries, circuit breakers, outbound auth (bearer, API key, OAuth 2.0 client credentials) and mTLS. |
provider-mocks | Deterministic in-memory providers. Development mode and the test suite run on these. |
orchestrator-runtime | The Runner: cart command dispatch, checkout execution, idempotency, inventory reservations, orders, the outbox and its background processor, dead-letter, inbox dedupe, webhooks and reconciliation. Store traits with in-memory, file-backed and PostgreSQL implementations. |
orchestrator-api | OrchestratorFacade, the one entry point every transport calls. Tenant-scoped authorization, AP2 mandate verification, UCP and ACP mapping, signing keys and HTTP message signature primitives, PII redaction. |
orchestrator-mcp | MCP tool definitions and the JSON-RPC handler, mapped onto the facade. |
orchestrator-http | The orchestrator-server binary: axum routes for REST, UCP, ACP, A2A and MCP, discovery documents, authentication, signature middleware, Web Bot Auth, the MPP 402 challenge flow, config loading and the OpenAPI document. |
orchestrator-observability | Tracing setup and the metrics helpers every crate uses. |
Request flow
Every transport ends in the same facade call, so a cart created over UCP can be checked out over A2A and behaves the same way.
sequenceDiagram
autonumber
participant Agent
participant HTTP as orchestrator-http
participant Facade as OrchestratorFacade
participant Runner
participant Providers as Your backends
Agent->>HTTP: POST /api/v1/... (UCP, ACP, A2A, MCP or REST)
HTTP->>HTTP: Authenticate (bearer or JWT) and resolve tenant
HTTP->>HTTP: Verify RFC 9421 signature and Content-Digest (when agent keys are configured)
HTTP->>Facade: Protocol shape mapped to a CartCommand or CheckoutRequest
Facade->>Facade: Authorize for the tenant, verify AP2 mandate (strict mode)
Facade->>Runner: dispatch_cart_command / execute_checkout
Runner->>Providers: catalog, pricing, tax, geo, payment, receipt
Providers-->>Runner: results
Runner-->>Facade: CartProjection or TransactionResult
Facade-->>HTTP: domain result
HTTP-->>Agent: protocol response, signed when signing keys are configured
Tenancy always comes from the authenticated caller, never from the request body. A cart remembers its owning tenant, and a caller authenticated for another tenant cannot read or check it out.
Cart lifecycle
Each cart mutation (add, update or remove an item, apply a code, select fulfillment) bumps the cart version and recalculates the cart against your backends in a fixed order: catalog lookup for a new item, pricing, tax, discounts, then the geo check. Each step appends an event to the cart’s event stream and advances the cart state machine.
stateDiagram-v2
[*] --> CartCreated
CartCreated --> ItemsMutated: item changed
ItemsMutated --> ItemsMutated: item changed
ItemsMutated --> Repriced: pricing resolved
Repriced --> Retaxed: tax resolved
Retaxed --> GeoChecked: geo validated
GeoChecked --> ItemsMutated: item changed
GeoChecked --> CheckoutReady: start checkout
CheckoutReady --> ItemsMutated: item changed
CartCreated --> CheckoutReady: start checkout
ItemsMutated --> CheckoutReady: start checkout
Repriced --> CheckoutReady: start checkout
Retaxed --> CheckoutReady: start checkout
CartCreated --> Cancelled: cancel
ItemsMutated --> Cancelled: cancel
Repriced --> Cancelled: cancel
Retaxed --> Cancelled: cancel
GeoChecked --> Cancelled: cancel
CheckoutReady --> Cancelled: cancel
Cancelled --> [*]
Any transition not drawn here is rejected. The state machine lives in orchestrator-core (next_cart_state) and has no side effects, so it is tested exhaustively on its own.
Checkout
Checkout is where money moves, so it re-reads everything instead of trusting the cart snapshot.
flowchart TD
A[Checkout request] --> B{Valid request?}
B -- no --> X1[400 validation error]
B -- yes --> C{Claim idempotency key<br/>tenant + merchant + key}
C -- completed before --> R1[Return the stored result]
C -- in flight --> X2[409 already in flight]
C -- claimed --> D{Cart owned by caller's tenant<br/>and version matches?}
D -- no --> X3[Release key, return error]
D -- yes --> E[Reprice: pricing, tax, discounts]
E --> F{Geo provider allows it?}
F -- no --> X4[Release key, GEO_BLOCKED]
F -- yes --> G{Payment amount equals<br/>the repriced total?}
G -- no --> X5[Release key, AMOUNT_MISMATCH]
G -- yes --> H[Reserve inventory]
H --> I{Policy engine allows it?}
I -- no --> R2[Rejected result, stored]
I -- yes --> J[Authorize payment<br/>Idempotency-Key forwarded]
J -- declined --> R3[AuthFailed result, stored]
J -- 3DS2 required --> P[Pause: AuthenticationRequired<br/>stored under the key]
P -. result from provider or agent .-> Q{Authenticated and<br/>cart unchanged?}
Q -- no --> R3
Q -- yes --> J2[Authorize with the result]
J2 -- declined --> R3
J2 -- authorized --> K
J -- authorized --> K[Commit, capture payment]
K --> L[Create order]
L --> M[Generate receipt]
M --> N[Enqueue order.created in the outbox]
N --> R4[Completed result, stored under the key]
The checkout state machine (next_checkout_state) walks Received → Validated → Priced → Taxed → GeoChecked → PaymentAuthorized → Committed → ReceiptGenerated → Completed, with the terminal failures Rejected, AuthFailed, CommitFailed and TimedOut. Each terminal state maps to the status of the TransactionResult.
stateDiagram-v2
[*] --> Received
Received --> Validated
Validated --> Priced
Priced --> Taxed
Taxed --> GeoChecked
GeoChecked --> PaymentAuthorized: authorized
GeoChecked --> AuthenticationPending: provider asks for 3DS2
AuthenticationPending --> PaymentAuthorized: authenticated, then authorized
AuthenticationPending --> AuthFailed: denied, declined or cart changed
AuthenticationPending --> TimedOut: not finished in time
GeoChecked --> AuthFailed: declined
PaymentAuthorized --> Committed
PaymentAuthorized --> CommitFailed
Committed --> ReceiptGenerated
ReceiptGenerated --> Completed
Received --> Rejected
Validated --> Rejected
Priced --> Rejected
Completed --> [*]
AuthenticationPending is the one state a checkout can stop in without finishing: the payment provider asked for 3DS2 step-up (see conformance: payment authentication). Its status is AuthenticationRequired, and the checkout’s request and pause are kept in the checkout_authentication store (and the cart’s event stream) until the result arrives. Reading the checkout asks the provider for the result; an ACP agent can also submit it. Either way the checkout resumes once, from the stored request.
Three checks guard the money:
- Amount integrity. The agent states the amount it expects to pay. If the repriced total differs, checkout fails with
AMOUNT_MISMATCHbefore any payment call, so a stale cart is never charged a different amount. - Geo is binding. The geo verdict is taken again at checkout, from the cart’s own destination, and a blocked destination stops the checkout.
- Version check. The request names the cart version it saw. A cart that changed since then fails with a version conflict.
Idempotency
Checkout is keyed on (tenant_id, merchant_id, idempotency_key).
- The first request claims the key and marks it in flight. A concurrent duplicate gets a conflict instead of a second charge.
- When the checkout reaches a result (completed, rejected or declined), the result is stored under the key. Replays return that stored result without calling any backend.
- A checkout paused for 3DS2 stores the pause under the key, so a replay returns the same pending step-up. When it resumes, the final result replaces the pause under the same key. The resume itself is claimed under
<key>#authentication, so two replicas reading the checkout at once cannot both place the order. - If checkout fails before anything was charged (validation, version conflict, geo block, amount mismatch), the key is released, so the caller can fix the request and retry with the same key.
- The key is forwarded to your payment provider as the
Idempotency-Keyheader on authorize, capture, void and refund, so a retry inside the orchestrator cannot double-charge either.
With PostgreSQL persistence the claim is a row in the database, so it holds across replicas.
Outbox, dead-letter and inbox
Side effects that leave the system, such as webhooks to subscribers, never happen inline with checkout. Checkout writes an order.created message to the outbox in the same flow that records the order, and a background processor delivers it.
flowchart LR
CO[Checkout completes] --> OB[(Outbox)]
OB --> P[Outbox processor<br/>claim, deliver]
P -- delivered --> ACK[Ack, remove]
P -- failed, attempts left --> BO[Back off, release] --> OB
P -- attempts exhausted --> DL[(Dead-letter)]
DL -- POST /api/v1/ops/dead-letter/replay --> OB
WH[Incoming event] --> IN{Inbox:<br/>seen message id?}
IN -- new --> ACC[Accept]
IN -- duplicate --> IGN[Ignore]
- Claim, then ack. The processor claims a message rather than removing it, and acknowledges it only once it is delivered or dead-lettered. A process that dies mid-delivery costs a retry, not the event. On PostgreSQL the claim uses
FOR UPDATE SKIP LOCKED, so every replica can run the processor. - Backoff. Failed deliveries back off exponentially, so a down endpoint does not burn the whole attempt budget in milliseconds.
- Dead-letter. After the maximum attempts the message moves to the dead-letter store. Operators list it and replay it, which resets the attempt count. See dead-letter handling and retries and outbox.
- Inbox.
POST /api/v1/events/incomingaccepts an event id at most once, so a provider that redelivers a webhook does not apply it twice. - Webhooks. Subscribers register per tenant and only receive their own tenant’s events. Deliveries are signed (RFC 9421) when signing keys are configured.
Persistence
All stores sit behind traits in orchestrator-runtime, with three implementations:
| Backend | When | Use it for |
|---|---|---|
| In-memory | Default in development | Tests, demos, local work |
| File-backed (JSON) | PERSISTENCE_PATH set in development | A local instance that must survive restarts |
| PostgreSQL | DATABASE_URL set, required with ENV=production | Production and anything with more than one replica |
The PostgreSQL schema is applied by orchestrator-server --migrate, which the Kubernetes manifests run as a Job before rollout.
Signing and verification
The orchestrator implements HTTP Message Signatures (RFC 9421) with Content-Digest (RFC 9530), as UCP requires.
- Inbound. When agent public keys are configured (
UCP_AGENT_KEYSorUCP_AGENT_JWKS), every/api/v1request must carrySignature-InputandSignatureheaders that verify against one of them, and a matchingContent-Digestwhen it has a body. - Outbound. When a signing key is configured (
UCP_SIGNING_KEY_ID,UCP_SIGNING_KEY), every response is signed over@statusand its body digest, and so is every webhook delivery. - Keys. Ed25519 or ES256. Public keys are published in the UCP business profile at
/.well-known/ucp. Previous keys stay verifiable bykidduring rotation (UCP_SIGNING_PREVIOUS_KEYS). - Agent identity. Web Bot Auth can additionally identify the agent operator from a signed request.
AP2 mandates and MPP payment credentials are verified separately, on checkout: AP2 in the facade (AP2_STRICT=1 fails closed), MPP through a 402 challenge bound to the request’s amount and body digest. Details are in the consumption guide.
Observability
Every provider call, checkout step, outbox delivery and signature check records Prometheus metrics through orchestrator-observability, labelled by outcome. The metrics are served at /metrics, and a Grafana dashboard ships in deploy/grafana. Logs are structured tracing output with PII redacted.