Introducing a new way to review your PRs.

Read the announcement

hatchet-dev / hatchet

🪓 An orchestration engine for background tasks, AI agents, and durable workflows

View on GitHub

31 documents · Updated Nov 23, 2026

docs / serverless-execution-platform

Serverless execution platform

The serverless execution platform lets a tenant run workflow tasks at HTTP-based endpoints without a long-running worker process. The API stores endpoint definitions, the engine selects and leases execution capacity, and the serverless operator discovers endpoint capabilities, delivers invocations, and reports durable task outcomes back to workflow execution. It also keeps a bounded history of important endpoint events for operational review.

Platform responsibilities

The platform joins endpoint management with the engine's worker model. Each enabled endpoint advertises the actions it can serve, while the operator presents the combined action set to the engine as a worker for its tenant.

The main responsibilities are:

  • Endpoint registration: Store endpoint URLs, signing data, limits, labels, and enabled state through the tenant API.
  • Capability discovery: Poll each owned endpoint to learn its workflows, actions, streaming options, and durable-task support.
  • Work placement: Lease tenant partitions to operator processes and open one engine registration for each served tenant.
  • Invocation delivery: Send ordinary work through signed HTTP and use a signed WebSocket for streaming or durable work.
  • Outcome durability: Convert endpoint results into engine task events so completion, failure, retry, cancellation, and re-invocation follow workflow rules.
  • Endpoint observability: Record meaningful health, catalog, and delivery events so operators can inspect endpoint history without storing one event for every poll.

The platform can run inside the engine or as a separate operator process. Both modes use the same serverless operator core and the same engine session model; only the host that opens the tenant session changes. See Serverless endpoints and operator runtime for the endpoint lifecycle and runtime behavior. See Public API contracts for the tenant-facing API and Repositories, messaging, and configuration for the shared data boundary.

System boundaries

The API owns endpoint configuration and tenant-visible status. The serverless operator owns live endpoint health, action discovery, leases, routing, delivery, and operational event recording. The engine remains the authority for task assignment and durable workflow state.

BoundaryResponsibilityResult
Tenant APICreate, list, update, and delete endpoint recordsA tenant can control where its tasks run
Serverless operatorLease tenant partitions and maintain endpoint stateWork has an active process owner
Endpoint event historyStore selected endpoint health and delivery eventsOperators can review recent endpoint behavior
Engine sessionAdvertise the action union and receive assigned actionsServerless capacity participates in normal scheduling
Endpoint contractReturn capabilities and accept signed invocationsUser code runs without direct engine access
Workflow enginePersist task events and durable entriesOutcomes survive retries, eviction, and process loss

References: api-contracts/…/endpoints.yaml• L1-240 pkg/…/core.go• L1-15 pkg/…/serverless.go• L17-28 pkg/…/serverless_event.go• L34-46

Endpoint management

Endpoint management gives each tenant a controlled target for serverless work. The API keeps the endpoint's public settings and status while protecting the signing secret and internal lease placement from API responses.

An endpoint defines a healthcheck URL and a trigger URL. The healthcheck discovers what the endpoint serves. The trigger URL receives assigned tasks after the operator has registered the discovered actions with the engine.

The endpoint resource exposes these product-level controls:

  • Kind: A generic HTTP endpoint or a runtime-specific endpoint such as Cloudflare Workers.
  • Execution limits: A request timeout, healthcheck interval, and inline durable-wait budget.
  • Routing controls: Labels and enabled state for worker placement and dispatch control.
  • Observed state: Last health result, error text, transition time, and registered actions.
  • Secret rotation: A write-only signing secret can be supplied when the endpoint is created or updated.

Deletion removes the endpoint from future routing while retaining a versioned record long enough for operator caches to observe the removal. This prevents a stale routing view from continuing to serve a deleted endpoint.

Endpoint event history

Endpoint event history gives the dashboard a tenant-scoped record of important operator observations. The operator records events when a health failure streak starts, health changes, the capability catalog changes, or delivery failures pass a rate limit. It does not write an event for every health poll.

Events carry a kind, message, time, and optional JSON details. Reads return one endpoint's newest events first, apply the tenant retention window, and can continue after a time marker. The event store is separate from task history, so it explains endpoint behavior without becoming the source of workflow state.

References: pkg/…/serverless_event.go• L23-46 pkg/…/serverless_event.go• L70-135 pkg/…/serverless_test.go• L1202-1259

References: api-contracts/…/serverless_endpoint.yaml• L11-190 api/…/serverless.go• L13-65 pkg/…/serverless_endpoint.go• L97-179 pkg/…/serverless_endpoint.go• L217-295

Lease and placement model

The operator divides a tenant's endpoints into lease units. A lease unit is one tenant and one partition. Processes claim units, and only the owning process loads those endpoints, polls them, and serves their tasks.

This model lets several operator processes share tenants without assigning the same unit twice. A process heartbeat proves that its leases are live. When the heartbeat expires, another process can claim the released units. Endpoint counts give the leaser a weight for fair sharing as it chooses claimable units. Units without the serverless entitlement are not counted or claimed.

When a process gains a unit, it loads the tenant's endpoint view and opens a tenant registration with the engine. When it loses the last unit for a tenant, it stops polling, pauses the registration, drains in-flight work, and closes the session. This keeps placement changes separate from the task state held by the engine.

The following flow shows how stored endpoint state becomes live execution capacity.

flowchart LR
    A[Endpoint API record] --> B[Tenant partition]
    B --> C[Process heartbeat]
    C --> D[Lease claim]
    D --> E[Endpoint routing view]
    E --> F[Healthcheck and capability catalog]
    F --> G[Tenant engine registration]
    G --> H[Assigned workflow action]

References: pkg/…/serverless.go• L30-34 pkg/…/serverless.go• L96-142 pkg/…/core.go• L76-80 pkg/…/runner.go• L279-380 pkg/…/runner.go• L431-485 pkg/…/serverless_test.go• L529-566

Capability discovery and routing

Capability discovery turns an endpoint healthcheck response into the action set that the engine can assign. The operator registers the endpoint's workflows and records the resulting actions, stream options, and durable support in the endpoint state.

The operator builds a tenant action union from all enabled endpoints. If several endpoints serve the same action, the engine sees one action while the operator keeps all eligible endpoints as routing choices. A delivery selects a healthy endpoint at random. If no endpoint is currently known healthy, it uses an enabled endpoint so a delayed health update does not stop work by itself.

An endpoint becomes unhealthy after repeated healthcheck failures. A successful check restores health and can change the action catalog. The operator applies catalog changes before it updates the tenant registration, so the engine's advertised actions and the local routing view move together.

References: pkg/…/endpoint.go• L25-27 pkg/…/endpoint.go• L152-239 pkg/…/endpoint.go• L264-338 pkg/…/routing.go• L191-223 pkg/…/routing.go• L929-973 pkg/…/serverless_endpoint.go• L374-394

Invocation delivery

Invocation delivery maps an engine-assigned action to an endpoint and returns one engine outcome. Ordinary tasks use a signed HTTP POST. Tasks that need engine streams or durable replay use a signed WebSocket with a first frame that identifies the task and invocation.

The delivery path is:

  1. The tenant registration receives a start action from the engine.
  2. The operator chooses an endpoint that advertises the action.
  3. The operator reports STARTED and sends the invocation using the endpoint's selected transport.
  4. The endpoint returns output, an error, a cancellation, or an eviction signal.
  5. The operator reports the result to the engine or leaves the task available for a later invocation when eviction or shutdown has no terminal outcome.

For HTTP delivery, a successful JSON response becomes task output. Non-success responses become permanent or retryable failures based on the status code, with an endpoint error body able to override the message and retry choice. The request sender also blocks unsafe destinations and bounds response size.

References: pkg/…/registration.go• L271-310 pkg/…/registration.go• L426-479 pkg/…/delivery.go• L23-30 pkg/…/delivery.go• L97-129 pkg/…/delivery.go• L155-200

Durable invocation flow

Durable invocation lets endpoint code pause a task while the engine records and resolves durable events. The endpoint re-runs the task for each invocation, and the operator replays the engine's durable responses over the WebSocket so the task can reach the same state without keeping process memory as its source of truth.

The socket also supports a limited set of engine streams. Endpoint code can open an allowed stream, receive engine messages, and close it. The operator uses its own engine credentials and checks the stream procedure and run access before forwarding data.

The durable lifecycle distinguishes terminal and non-terminal outcomes:

Endpoint or operator resultEngine behavior
done with outputComplete the task with the JSON output
done with errorFail the task and apply the retry flag
evictedRecord no terminal task event and invoke the task again when its awaited entry is ready
Engine cancellationReport cancellation once and stop the invocation
Operator shutdown before doneLeave the task available for reassignment

The first frame carries the assigned action, invocation count, and inline wait budget. Durable requests and responses travel only on durable task sockets, while stream frames can travel on both durable and streaming task sockets.

References: api-contracts/…/serverless.proto• L102-199 pkg/…/registration.go• L481-594 pkg/…/delivery.go• L55-74 pkg/…/durable_delivery_test.go• L87-202

Outcome reporting

Outcome reporting converts endpoint behavior into the engine's task event model. The operator sends STARTED before delivery and then reports completion or failure through the tenant session, so the engine can apply its normal retry and workflow rules.

The engine owns durable history and task state. The serverless operator only relays durable requests and endpoint responses. This boundary allows a process to restart or lose a lease without losing the workflow's durable record; a new worker can receive the task and continue from the engine state.

Endpoint event history records the operator's view of health and delivery problems. It supports diagnosis, but it does not replace the engine event stream that decides whether a task is complete, retryable, cancelled, or ready for re-invocation.

Cancellation has a single terminal report. A shutdown that interrupts delivery reports a retryable failure when the task has not already been cancelled. A durable eviction or operator shutdown reports no terminal event because the task must remain eligible for a later delivery.

References: pkg/…/registration.go• L596-610 pkg/…/delivery.go• L55-74 pkg/…/registration.go• L790-843 pkg/…/core.go• L159-186 pkg/…/serverless_event.go• L34-46

Runtime modes

The platform supports an in-engine mode and a separate operator mode. In both modes the serverless core leases itself, opens tenant sessions, and uses the same endpoint contract; the difference is where the core runs and how it reaches the engine.

The engine can supervise its in-process core and restart it after an unexpected stop. A separate operator uses the remote operator host and its own process heartbeat. In either mode, graceful shutdown releases leases before registrations drain and close, so the engine can move work to another live worker.

References: pkg/…/core.go• L1-15 cmd/…/serverless.go• L30-48 cmd/…/serverless.go• L76-98

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to endpoint fields must keep the API schema, stored row, transformer, cache refresh, and endpoint contract aligned.
  • Changes to healthcheck capability fields must update registered actions, stream actions, durable support, the tenant action union, and endpoint routing together.
  • Changes to endpoint event kinds, details, or retention must preserve tenant and endpoint scoping, newest-first reads, and the separation between operational history and task history.
  • Changes to partition or lease rules must preserve process liveness, fair-share counts, entitlement filtering, takeover behavior, and the rule that only the owner serves a unit.
  • Changes to action registration must keep the engine's advertised action union consistent with the local endpoint candidates used for delivery.
  • Changes to HTTP status mapping or WebSocket done frames must preserve the engine's retry, cancellation, eviction, and output contracts.
  • Changes to durable frame ordering or stream permissions must remain compatible with the serverless protocol and the engine's durable event model.
  • Changes to shutdown ordering must release new assignments before draining existing deliveries, then close sessions and process ownership.

Important failure modes

TriggerConsequenceGuard
A process heartbeat expiresAnother process can take the tenant units while the old process must stop serving themClaim leases using database liveness and release units when process rows expire
A healthcheck fails repeatedlyThe endpoint becomes unhealthy and is avoided when another healthy endpoint serves the actionRequire repeated failures before the transition and one success to restore health
A catalog changes but the engine action union does notThe engine can assign work the local router cannot serve, or stop assigning newly served workApply the catalog and synchronize the registration action delta as one capability change
No enabled endpoint serves an assigned actionThe task cannot be delivered from the current routing viewReport a retryable routing failure so the engine can assign it again
An endpoint returns a non-JSON success bodyThe task cannot produce valid JSON outputTreat the response as a permanent failure
A durable socket closes without a done frameThe invocation has no terminal outcomeReport a retryable failure unless cancellation or shutdown already owns the next action
A durable invocation is evicted while waitingA terminal task event would incorrectly end a task that must resumeRe-invoke from the engine's durable log when the awaited entry is ready
An event batch contains details that cannot be storedThe batch fails instead of silently recording only part of the operator historyClassify row-value errors so the caller can retry valid events separately
An event is outside the tenant retention windowThe event is not returned in endpoint historyApply the retention start to every event read
Shutdown closes a registration before its deliveries drainIn-flight work can stop without a result or be reassigned too earlyPause assignment, drain up to the limit, then close the session

Key files

FileWhy to read it
api-contracts/…/endpoints.yamlDefines the tenant API for endpoint lifecycle management
api-contracts/…/serverless_endpoint.yamlDescribes endpoint settings and the status visible to tenants
api-contracts/…/serverless.protoDefines healthcheck, trigger, WebSocket, durable, and stream messages
pkg/…/serverless.goShows the data boundary for endpoints, tenants, processes, leases, and endpoint events
pkg/…/serverless_endpoint.goShows how endpoint settings, partition membership, status, and capability changes become stored state
pkg/…/serverless_event.goDefines the operational event history used to inspect endpoint behavior
pkg/…/core.goExplains the operator's shared lifecycle and deployment modes
pkg/…/runner.goConnects leases to tenant registrations, routing state, and shutdown
pkg/…/endpoint.goShows health polling and capability registration at a high level
pkg/…/routing.goExplains the endpoint action union and delivery selection model
pkg/…/registration.goConnects engine actions to delivery and task outcome reporting
pkg/…/delivery.goDefines signed HTTP delivery and response-to-outcome mapping
pkg/…/serverless_test.goVerifies endpoint state, lease ownership, entitlement filtering, event retention, and concurrent assignment contracts
cmd/…/serverless.goShows how the engine starts and supervises the in-engine operator
docs/serverless-endpoints-and-operator-runtime.mdChild page for detailed endpoint management and operator runtime behavior
docs/public-api-contracts.mdRelated page for the API boundary used by endpoint management
docs/repositories-messaging-and-configuration.mdRelated page for repository and shared data boundaries