External integrations and events
External integrations connect outside systems to Hatchet workflows and platform services. They receive signed messages, map external data to tenant-scoped events, send workflow notifications, and expose actions such as Slack operations. The main boundary is an integration contract that keeps authentication and data handling separate from workflow dispatch.
This page complements Developer products and integrations. See Language SDKs for the client-facing event and workflow APIs.
Integration boundary
The integration boundary defines how a provider identifies itself, exposes actions, and optionally accepts webhooks. An integration webhook supplies its HTTP method and paths, checks the request, selects a workflow action, and returns the event data that the workflow can use. The shared contract is defined in pkg/…/integration.go.
The boundary also gives authentication failures an HTTP status. This lets an adapter reject an untrusted request without treating it as a platform error. Provider-specific code can therefore use its own signature or token rules while the rest of the system handles the result in one way.
References: pkg/…/integration.go• L9-57
Inbound event ingestion
Inbound adapters turn messages from external event sources into tenant-owned workflow events. AWS Simple Notification Service (SNS) is the clearest example: the platform verifies the signed message, checks that its topic belongs to the tenant, handles subscription control messages, and sends normal notifications to the event ingestor.
The SNS path follows this sequence:
flowchart LR
A[AWS SNS POST] --> B[Parse SNS payload]
B --> C[Verify AWS signature and certificate URL]
C --> D[Match tenant and Topic ARN]
D --> E{Message type}
E -->|Subscription confirmation| F[Confirm subscription]
E -->|Unsubscribe confirmation| G[Complete unsubscribe]
E -->|Notification| H[Ingest event for workflow triggers]
An SNS integration is registered for a tenant by its Topic ARN. A message is accepted only when its signature is valid and that ARN is registered for the tenant. Subscription and unsubscribe messages control the external connection; other messages preserve the received body as the event input for the configured event route.
References: api/…/sns.go• L15-74 api/…/sns_create.go• L13-39 pkg/…/sns.go• L11-24
SNS trust boundary
SNS authentication depends on a signed payload and a signing certificate fetched from an AWS SNS HTTPS host. The adapter restricts certificate and subscription URLs to HTTPS SNS domains before it makes outbound requests. This protects the inbound path from accepting forged messages or using message URLs as an arbitrary network target.
References: internal/…/sns.go• L20-37 internal/…/sns.go• L68-93 internal/…/sns.go• L103-145 internal/…/sns.go• L148-202
Webhook request handling
Shared webhook utilities provide a common boundary for adapters that receive JSON bodies and query parameters. They decode both sources into a request model, validate the model, and return a consistent client or server error. This keeps provider adapters focused on provider rules and event meaning.
The same boundary supports two response paths. Public handlers can write a structured error, while internal callers can receive the error and decide how to report it. Responses are encoded as JSON, and failures are logged and sent to the platform alert path when they are server errors.
References: pkg/…/decoder.go• L16-65 pkg/…/decoder_validator.go• L12-93 pkg/…/errors.go• L17-75 pkg/…/writer.go• L14-41
Workflow event production
The event client is the producer side of the workflow trigger path. It accepts a key and JSON payload, adds tenant namespace and optional metadata, then sends the event to the event service. The service uses the key to find workflows that subscribe to that event.
Event production also carries context across workflow boundaries. Trace data and source workflow or step identifiers can travel with the event, so a triggered run can be linked to the step that emitted it. Bulk production uses the same contract for several events in one request, while stream events and task logs support run output rather than workflow triggering.
The older pkg/…/event.go package is deprecated. New integrations should use the Go SDK event API described on the Language SDKs page.
References: pkg/…/event.go• L24-61 pkg/…/event.go• L86-111 pkg/…/event.go• L166-231 pkg/…/event.go• L234-290 pkg/…/event.go• L331-365
Event payload access
Event payload access is the read side of the workflow event path. It lets an authorized member inspect the data stored with an event while keeping payloads behind the platform's payload-view permission. The same access rule applies to both direct event lookup and tenant-scoped lookup.
The response presents the stored event data as the event payload. If the event is missing, the service returns a not-found result; if the caller lacks payload access, it returns a forbidden result instead of exposing the data.
References: api/…/get_data.go• L12-37 api/…/get_data.go• L40-67
Outbound provider actions
Outbound integrations let workflow actions affect external systems. The Slack integration maps named actions to private channel creation, user invites, and message delivery. It keeps the provider token and team context inside the integration while workflows pass typed action data.
The action model has two parts:
- The integration declares its stable identifier and supported action names.
- The action handler sends the request to the provider and returns a provider result or error.
Slack currently exposes actions but no inbound webhook handlers. This makes it an outbound action integration rather than an event source.
References: pkg/…/slack.go• L12-53 pkg/…/slack.go• L55-108
Notification delivery
Email integrations deliver platform notifications through a provider-neutral service. The service defines messages for tenant invites, failed workflow alerts, expiring token notices, resource limit alerts, organization invites, and magic links. Providers receive a template name and model data, so the alerting code does not depend on SMTP or Postmark details.
SMTP and Postmark are two delivery paths behind this same contract. Providers support direct recipients, blind-copy delivery, and reusable template sends. Postmark also sends magic-link messages through the shared template contract. A no-op service provides a safe disabled path when email delivery is not configured.
References: pkg/…/email.go• L9-105 pkg/…/smtp.go• L26-77 pkg/…/smtp.go• L80-133 pkg/…/postmark.go• L16-87
Integration observability
External event paths need visibility into delivery cost, transit delay, and subscriber pressure. The Prometheus integration measures publish time, publish-to-delivery transit, stale messages, active handlers, handler wait, NATS scheduler partition state, and database fairpool pressure. Fairpool metrics show wait time, rejected acquires, held connections, and connection limits. Tenant-scoped metric collection can be gated by entitlement. In that mode, an entitlement lookup error fails closed so the tenant's metrics are not collected.
The metrics describe different points in the event path. Publish and transit metrics show time spent before and during delivery. Handler and pending metrics show subscriber load. Stale-skip and drop counters show messages that did not reach a handler. Fairpool metrics show when database connection capacity delays or rejects work and how much capacity each shared or tenant bucket holds. Durable Task budget metrics show how long streams wait for in-flight request capacity and whether they acquire it or end while waiting. They separate stream and tenant budgets without using tenant IDs as labels, which keeps the metric series bounded.
The Prometheus server exposes the shared registry over HTTP. Services in one process can request the same address without starting duplicate listeners. Each caller receives a stop function, and the server shuts down only after the last caller releases it.
References: pkg/…/pubsub.go• L8-81 pkg/…/gate.go• L10-54 pkg/…/db_pool.go• L8-38 pkg/…/durable_task.go• L8-17 pkg/…/server.go• L20-59 pkg/…/server.go• L62-93
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the tenant binding and external identifier contract aligned between the SNS API, repository lookup, and inbound message handler.
- Keep each event adapter's authentication result mapped to the HTTP behavior expected by its external sender.
- Keep event metadata changes compatible with trace propagation and source workflow or step linking.
- Keep event payload access paths aligned with the payload-view permission and both event lookup scopes.
- Keep email template names and template model fields aligned across the shared email contract and both provider paths.
- Keep new email message types, such as magic-link messages, mapped to provider templates in every configured delivery path.
- Keep integration action names aligned with the worker action registration path and the provider handler mapping.
- Keep provider URL allowlists aligned with every outbound URL that an authenticated inbound message can request.
- Keep Prometheus metric labels and metric meaning aligned with the publish, delivery, handler, and scheduler paths that report them.
- Keep database fairpool metric labels aligned with tenant and shared bucket semantics, and keep rejection counters free of tenant IDs to avoid unbounded series growth.
- Keep scheduler metric registration paired with its unregister function so a subscription does not register the same metric twice.
- Keep Durable Task budget metric labels limited to budget type and wait outcome so tenant cardinality stays bounded.
- Keep Prometheus server start and stop calls balanced so shared listeners stop only after all users release them.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| An SNS message has an invalid signature or signing certificate URL | The message is not trusted and cannot start a workflow event | Verify the AWS signature and require an HTTPS SNS certificate host before processing |
| An SNS Topic ARN is not registered for the receiving tenant | A valid external message cannot be mapped to a tenant | Look up the tenant and Topic ARN pair before event ingestion |
| An SNS subscription URL is outside an AWS SNS HTTPS host | A control message could cause an unsafe outbound request | Validate the scheme and host before subscription or unsubscribe calls |
| An event payload cannot be JSON encoded or its metadata cannot be merged | The event is not sent to the event service | Return the encoding error and mark the producer operation as failed |
| A caller lacks payload-view permission | Event data is not returned | Enforce the permission check before reading either event lookup result |
| A tenant entitlement lookup fails for scoped Prometheus metrics | Metrics are skipped for that tenant | Fail closed and log the entitlement lookup error |
| A delivered message exceeds its topic kind's maximum age | The handler does not run and the stale-skip count increases | Track the published timestamp and apply the topic age limit before handler execution |
| A NATS scheduler subscription exceeds its client-side pending limit | Messages are dropped before the subscriber receives them | Expose the drop count and pending depth so operators can detect the loss |
| A scheduler metric is registered more than once | Prometheus registration panics | Register once per subscription and call the returned unregister function during teardown |
| A fairpool rejection counter uses a tenant ID label | The process creates a growing time series for each tenant | Keep rejection counters labeled by pool and bucket only |
| A Durable Task budget wait metric adds a tenant ID label | High tenant count creates unbounded metric series | Keep the histogram labeled only by budget type and wait outcome |
| A provider template is missing or produces an empty subject | Email delivery fails before the message is sent | Resolve the template and require a non-empty subject |
| Multiple services request the same Prometheus address and one caller stops | Metrics become unavailable to the remaining service | Reference-count shared servers and stop them only after the last caller releases its stop function |
| A Postmark request returns a non-success status | The notification is not delivered | Return the provider response as an error so the caller can handle delivery failure |
Key files
| File | Why to read it |
|---|---|
| pkg/…/integration.go | Defines the common action and webhook boundary for integrations. |
| api/…/sns.go | Shows how a verified external message becomes a tenant event or subscription action. |
| internal/…/sns.go | Shows the trust rules for AWS SNS signatures and callback URLs. |
| pkg/…/decoder_validator.go | Shows the shared decode-and-validate boundary for webhook requests. |
| pkg/…/event.go | Shows the event producer contract and context carried into triggered workflows. |
| api/…/get_data.go | Shows the permission boundary for reading stored event payloads. |
| pkg/…/slack.go | Shows how an external provider exposes workflow actions. |
| pkg/…/email.go | Defines provider-neutral notification types and delivery operations. |
| pkg/…/postmark.go | Shows the HTTP-based email delivery path. |
| pkg/…/smtp.go | Shows the SMTP-based email delivery path. |
| pkg/…/gate.go | Shows tenant-aware control of integration metrics. |
| pkg/…/pubsub.go | Shows the measures for publish, delivery, handler load, stale messages, and scheduler state. |
| pkg/…/db_pool.go | Defines database fairpool metrics for wait time, rejected acquires, held connections, and connection limits. |
| pkg/…/durable_task.go | Defines the bounded labels and outcomes for Durable Task budget wait time. |
| pkg/…/server.go | Shows how services share and shut down the Prometheus HTTP endpoint. |