Durable stream contracts and clients
Durable stream contracts give applications a stable way to publish bytes to tenant-scoped topics and consume those bytes with replay and resume support. The protobuf service defines the wire shape, generated bindings expose it over Connect-compatible transports, and the Go, Python, and TypeScript clients turn it into application-facing publish, metadata, reset, and event-reading APIs.
Contract model
The stream contract has unary publish, batch publish, metadata, and reset operations plus a server-streaming subscribe operation. A topic is addressed by a tenant-owned namespace and topic name. A cursor marks a position after a stored message so a consumer can continue without choosing a new topic position by guesswork.
Publish contract
V1Streams.Publish accepts a namespace, topic, producer ID, and producer sequence together with either inline bytes or a payload reference. The empty response means that the service accepted the message for storage. The producer fields let the service recognize a retry and reject a skipped sequence instead of silently changing the producer's order.
V1Streams.PublishBatch carries several consecutive entries in one request. The request gives the first producer sequence, and each later entry uses the next sequence. Clients can use this form to keep per-topic order while reducing request overhead. Each entry still uses either inline bytes or a payload reference.
Large payloads can use payload_ref instead of sending all bytes in one gRPC message. The TypeScript and Python clients manage this choice through the stream payload upload service, while the stream contract keeps the stored message linked to its payload.
References: api-contracts/…/streams.proto• L9-22 sdks/…/streams.ts• L13-46 sdks/…/streams_pb.ts• L20-53 sdks/…/streams.ts• L14-27 sdks/…/streams.py• L31-47
Subscribe contract
V1Streams.Subscribe accepts a namespace and topic, with an optional cursor. Without a cursor, reading starts at the oldest retained message unless the topic has been reset. With a cursor, reading starts after that position. The server sends batches of StreamEntry values, each with a cursor and storage time. An entry can carry inline bytes or a payload reference.
The response can also carry hangup. A hangup is a clean end for an idle subscription. Its cursor is the latest resume point. A client can use that cursor in a later subscription instead of treating the end as data loss.
References: api-contracts/…/streams.proto• L24-40 sdks/…/streams.ts• L48-68 sdks/…/streams_pb.ts• L78-161 sdks/…/streams.ts• L29-47 sdks/…/streams.py• L676-732
Topic metadata contract
V1Streams.GetTopicMetadata describes the retained part of a topic without reading its messages. The result identifies the topic and tenant, reports the retained message count and latest publish time, and provides a latest cursor when the topic has retained messages.
References: sdks/…/streams.ts• L70-85 sdks/…/streams_pb.ts• L164-231 sdks/…/streams.ts• L49-64 sdks/…/streams.py• L610-655
Topic reset contract
V1Streams.Reset changes the starting boundary for future subscriptions that do not provide a cursor. It does not stop readers that are already iterating, and it does not change readers that provide a cursor. This gives an application a way to start a new logical run on one retained topic while existing readers continue to follow the topic.
References: sdks/…/streams.ts• L87-95 sdks/…/streams_pb.ts• L234-305 sdks/…/streams.ts• L66-71 sdks/…/streams.ts• L356-361 sdks/…/streams.py• L657-674
Connect and generated bindings
The protobuf file is the source contract for the service and its message types. Code generation produces language-specific messages and service clients from that source. Application code should use the generated surface or an SDK feature client rather than edit generated files.
Connect service surface
The service name is v1.V1Streams. Its procedures are /v1.V1Streams/Publish, /v1.V1Streams/PublishBatch, /v1.V1Streams/Subscribe, /v1.V1Streams/GetTopicMetadata, and /v1.V1Streams/Reset. Publish, batch publish, metadata, and reset use unary calls. Subscribe uses a server stream. The handler supports Connect, gRPC, and gRPC-Web with binary Protobuf and JSON codecs.
The TypeScript SDK creates the full generated service client from the stream service definition and a selected transport. This includes the server-streaming Subscribe call, so the feature client can use the same transport contract for publishing and reading.
References: internal/…/streams.connect.go• L23-71 internal/…/streams.connect.go• L94-129 sdks/…/rpc.ts• L1-11 sdks/…/streams_pb.ts• L269-305 sdks/…/streams.ts• L944-1019
Generated language bindings
The Go bindings provide Protobuf message types and the Connect service client used by the shared Go client. TypeScript has generated views for the main SDK and the serverless SDK. These views preserve the single-message and batch publish forms, the subscribe stream, topic metadata, and reset operations. They also preserve the choice between inline payload bytes and a payload reference.
References: internal/…/streams.pb.go• L1-34 sdks/…/streams.ts• L14-71 sdks/…/streams.ts• L298-424 sdks/…/streams.ts• L1250-1322 sdks/…/streams.ts• L13-46
Frontend REST stream access
The generated frontend HTTP client exposes the tenant-scoped payload transfer and topic listing needed by browser-facing stream views. Payload upload and fetch support messages that do not fit the inline publish path. Topic listing gives a tenant-level view of retained topics; it is separate from live Connect subscription.
References: frontend/…/Api.ts• L783-869
Client access
The client APIs keep the wire contract small while adding the behavior that application code needs. The shared Go client exposes callback and channel forms with explicit resume control. The Python client adds async publishing and consumption with payload transfer and retry handling. TypeScript exposes publishing, topic metadata, reset, and an async iterator with built-in reconnect behavior for transient stream failures. The core TypeScript client also supports durable topic publishing and control calls, while a narrower construction can provide only run-scoped publishing.
Go client
The shared Go client publishes with a context, namespace, topic, and byte payload. It creates a producer identity per namespace and topic, serializes publishes for that address, and advances its sequence only after a successful store. An uncertain failure starts a new producer identity so a later payload is not sent under a sequence that may already have been stored.
References: pkg/…/streams.go• L18-32 pkg/…/streams.go• L84-117
Python client
The Python StreamsClient publishes bytes or UTF-8 text to durable topics and returns after storage. It keeps publishes ordered per namespace and topic, groups queued messages into bounded batch requests, and uploads payloads above the inline limit before storing their references. It also exposes topic metadata and reset calls.
Its async subscribe iterator yields payloads with cursors and storage times. Temporary transport or payload-service failures cause a bounded resubscribe from the last yielded cursor. Permanent errors such as an expired cursor or missing stream access are returned to the caller. A server hangup ends the iterator cleanly.
References: sdks/…/streams.py• L31-47 sdks/…/streams.py• L551-732
TypeScript client
The v1 TypeScript client exposes hatchet.streams.publish, hatchet.streams.topicMetadata, hatchet.streams.reset, and hatchet.streams.subscribe. events is an alias for subscribe and is kept for compatibility while callers move to the clearer name. publish accepts text or bytes and keeps calls ordered per namespace and topic. It uploads payloads that are larger than the inline gRPC budget, then publishes the returned reference. Queued messages can share a batch request, with a single-message fallback for older engines. topicMetadata reports the retained topic view. reset changes where later no-cursor readers start. subscribe yields StreamEvent values with payload, cursor, and optional storage time.
When a connection drops, subscribe resubscribes from the last cursor it yielded. It uses bounded backoff for retryable transport and payload-fetch failures, so transient loss does not skip or repeat messages. An expired cursor or another non-retryable error is raised to the caller. An abort signal, caller stop, or clean server hangup ends iteration without an error.
References: sdks/…/streams.ts• L41-90 sdks/…/streams.ts• L160-227 sdks/…/streams.ts• L230-274 sdks/…/streams.ts• L327-429 sdks/…/rpc.ts• L1-11 sdks/…/streams.test.ts• L23-145 sdks/…/streams.test.ts• L358-494
Core TypeScript client
The core TypeScript StreamsClient supports both task-run stream chunks and durable topic calls when it is built with the events and streams services. Its durable publish accepts text or bytes, orders calls per namespace and topic, and can batch queued messages. It rejects empty payloads and payloads above the inline limit before sending them. It does not upload large payloads. topicMetadata and reset provide the same durable topic controls as the v1 client.
The client retains producer state for a bounded number of topics. It advances a topic sequence only after storage succeeds and rotates the producer identity after an uncertain failure. A client built with only the events service still supports task-run publishing, but durable topic calls are unavailable. If the engine does not support batch publish, the client falls back to ordered single-message calls. If a durable message uses a payload reference, the client also needs a payload fetch function to deliver its bytes.
References: sdks/…/streams.ts• L9-33 sdks/…/streams.ts• L55-101 sdks/…/streams.ts• L122-185 sdks/…/streams.ts• L228-352
Run-scoped stream distinction
The core TypeScript StreamsClient.put API publishes chunks to the stream of one task run, like ctx.putStream, and can use an event index to order concurrent chunks. It does not publish to the retained namespace and topic contract described on this page.
References: sdks/…/streams.ts• L55-64 sdks/…/streams.ts• L105-120 sdks/…/streams.ts• L93-97
Publishing and consumption behavior
An application normally publishes a message and receives a completion only after the service stores it. A consumer then reads retained history and follows the topic's live end. The cursor returned with each entry is the application checkpoint for the next read.
Application usage patterns
An application can publish from a workflow or from any other client process because durable topics are independent of a task run. A reader can stop when its business work is complete, save an event cursor, and later resume after that cursor. A retrying workflow can reset a topic before a new attempt so readers that start later see only the current attempt, while readers already attached can observe the full history.
The TypeScript examples show the main application choices:
- Start a reader before or after publishing. A new reader reads retained messages unless the topic has been reset.
- Use a cursor to continue after the last event received.
- Use an abort signal or stop an async iterator to end consumption cleanly.
- Use a namespace to keep topics with the same name separate.
- Reset a topic to its latest event or to a chosen cursor when a new logical starting point is needed.
References: sdks/…/run.ts• L7-114 sdks/…/workflow.ts• L4-47 sdks/…/durable-streams.e2e.ts• L21-127 sdks/…/durable-streams-retry.e2e.ts• L31-51
This diagram shows the application path from a publish call to upload or inline delivery, batch or single-message storage, replay, live delivery, and resume.
sequenceDiagram
participant A as Application
participant C as Client
participant U as Payload service
participant S as Stream service
participant T as Retained topic
A->>C: publish(topic, payload)
alt payload fits inline budget
C->>S: Publish or PublishBatch
else payload needs upload
C->>U: upload payload
U-->>C: payload reference
C->>S: Publish or PublishBatch with reference
end
S->>T: store message
S-->>C: publish complete
A->>C: subscribe(topic, optional cursor)
C->>S: Subscribe(namespace, topic, cursor)
S-->>C: retained and live entries with cursors
opt entry has payload reference
C->>U: fetch payload
U-->>C: payload bytes
end
C-->>A: event payload and cursor
A->>A: save latest cursor
The service keeps the stored topic as the source of truth. Live subscribers may receive a wake-driven update or a later poll, but a lost wake does not change the stored data. Multiple consumers can read the same topic from different cursors.
References: api-contracts/…/streams.proto• L9-40 internal/…/server.go• L24-90 internal/…/topic_poller.go• L193-264 sdks/…/streams.ts• L160-199 sdks/…/streams.ts• L382-429
Limits and access rules
Stream requests are subject to both contract validation and tenant resource policy. The service checks the durable-stream entitlement before publish or subscribe, then checks address, payload, topic, and message limits before it stores a message. The v1 TypeScript and Python clients apply the upload limit before they send a large payload, while the core TypeScript client rejects payloads above its inline limit because it has no upload path.
The main application-visible limits are:
| Limit | Value or rule | Result |
|---|---|---|
| Topic name | Required and at most 255 characters | Invalid address is rejected. |
| Namespace | Optional and at most 255 characters | Invalid address is rejected. |
| Inline payload | Non-empty and at most 4,189,184 bytes | Larger payloads use the upload path in the v1 TypeScript and Python clients. |
| Uploaded payload | At most 64 MiB in the v1 TypeScript and Python clients | Larger messages are rejected before upload. |
| Python batch | At most 500 entries and within the gRPC request budget | Queued publishes split into more than one request. |
| Core TypeScript publish payload | Non-empty and at most 4,189,184 bytes | Larger messages are rejected before a request is sent. |
| Core TypeScript producer state | At most 1,024 tracked namespace-topic pairs | Older entries are evicted and later use a new producer identity. |
| Topics per tenant | Default 100,000 | A new topic can be rejected when the tenant limit is reached. |
| Messages per tenant | Default 10,000,000 in a 24-hour window | A publish can be rejected when the message limit is reached. |
| Retained history | Tenant-configured; default tenant retention is 720 hours | Old messages leave the replay range. |
The topic and message values are defaults and can be changed by configuration or tenant policy. A cursor older than the retained range cannot safely resume because doing so could skip deleted messages. The service reports that condition as an out-of-range failure rather than silently starting later.
References: internal/…/server.go• L28-60 pkg/…/streams.go• L21-38 pkg/…/streams.go• L40-72 pkg/…/limits.go• L5-33 pkg/…/streams.go• L124-139 sdks/…/streams.ts• L41-53 sdks/…/streams.ts• L294-318 sdks/…/streams.ts• L9-27 sdks/…/streams.ts• L137-149 sdks/…/streams.ts• L301-316 sdks/…/streams.py• L31-47 sdks/…/streams.py• L233-245 sdks/…/streams.py• L551-579
Related systems
Durable topic streams are one part of the platform's event access model. The parent page explains storage, retention, polling, and batching. The public API page places HTTP stream payload and topic access beside the other external contracts. The language SDK page places the Go, Python, and TypeScript client features beside the other SDK responsibilities. The repository and configuration page explains the limits and stored stream data that shape client behavior.
Change checklist
When these files or sections are changed, remember to consider these:
- Keep protobuf field numbers, batch entry sequence rules, and stream method kinds aligned with the generated Go, TypeScript, and serverless bindings.
- Keep payload and payload-reference handling aligned across the stream contract, upload and fetch services, and the TypeScript and Python clients. Preserve the difference between the v1 upload path and the core client's inline-only path.
- Keep cursor encoding, cursor ownership of namespace and topic, and client resume behavior aligned across the service and SDKs.
- Keep producer ID and sequence rules aligned with retry handling so an ambiguous publish cannot store a later payload under an uncertain sequence.
- Keep batch fallback behavior aligned with producer sequence advancement and per-call settlement when an older engine does not support
PublishBatch. - Keep inline, uploaded, and core-client payload limits aligned with each client's routing and the transport message budget.
- Keep Connect procedure names, the TypeScript transport adapter, and supported transport behavior aligned with SDK transport construction.
- Keep reset semantics aligned across the service contract, new no-cursor subscriptions, existing readers, and retry workflows.
- Keep durable topic streams distinct from run-scoped
putStreamAPIs when changing either TypeScript client surface. - Keep core publish batching and its fallback for older engines aligned with producer sequence advancement and per-call settlement.
- Keep the
subscribeand compatibilityeventssurfaces aligned so cancellation, hangup, reconnect, and cursor behavior stay the same. - Keep generated frontend payload and topic-list routes aligned with the HTTP contract when stream payload or topic management endpoints change.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Durable-stream entitlement is disabled | Publish and subscribe return permission denied | Enable the tenant entitlement before using the topic client. |
| Publish payload is empty or exceeds the supported size | The message is not stored | Validate payload size before calling publish; use the v1 or Python upload path for payloads above the inline budget, or use the core client only within its inline limit. |
| Topic or namespace is empty or too long | The request is rejected | Use a required topic and addresses within 255 characters. |
| Publish batch is not supported by an older engine | The client retries in ordered single-message calls | Keep the client fallback enabled and preserve producer sequence order. |
| Publish ends with an ambiguous transport error | The message may be stored even though the caller sees an error | Let the client rotate its producer identity before the next payload. |
| Payload upload or fetch receives a temporary HTTP failure | The publish or event delivery is delayed and may retry | Allow the bounded client retry and backoff policy to run. |
| Core client receives a payload reference without a fetch function | Subscription fails when it reaches that message | Build the client with a payload fetch function when it must read uploaded messages. |
| Consumer uses a cursor outside the retained range | Subscribe returns an out-of-range error instead of silently skipping messages | Restart from the oldest retained position or apply an application recovery policy. |
| TypeScript or Python subscription receives a non-retryable status | The iterator raises | Handle expired cursors and access errors separately from transient transport failures. |
| Metadata is requested for a topic with no published messages | The metadata call returns not found | Treat metadata as a description of an existing retained topic. |
| Tenant topic or message limit is reached | Topic creation or publish is rejected | Monitor tenant limits and reduce or pace stream use. |
| A new reader starts without a cursor after a topic reset | It skips messages before the reset boundary | Use a saved cursor or another topic when the reader needs earlier history. |
| Core client is built with only the events service | Durable topic calls fail before reaching the service | Build StreamsClient with both the events and streams services for durable topic access. |
| Core client evicts a topic producer from its tracking cap | The next publish uses a new producer identity | Treat the cap as a memory bound; rely on the new producer identity to preserve order. |
Key files
| File | Why to read it |
|---|---|
| api-contracts/…/streams.proto | Defines the durable stream messages and the publish, batch publish, subscribe, metadata, and reset RPCs. |
| internal/…/server.go | Shows access checks, validation, publish acceptance, cursor resolution, and subscription outcomes. |
| internal/…/streams.connect.go | Shows the generated Connect routes, client methods, and supported transports. |
| pkg/…/streams.go | Shows the shared Go publish sequencing and subscription callback behavior. |
| sdks/…/rpc.ts | Shows how the TypeScript SDK exposes the generated stream service over its Connect transport. |
| sdks/…/streams.ts | Shows the main TypeScript message shapes, codecs, and service client contract. |
| sdks/…/streams.ts | Shows the serverless TypeScript message bindings, including single and batch publish payloads. |
| sdks/…/streams_pb.ts | Shows the descriptor-based TypeScript contract, method kinds, and reset operation. |
| frontend/…/Api.ts | Shows the frontend HTTP access for stream payload transfer and topic listing. |
| sdks/…/streams.ts | Shows TypeScript publishing, payload transfer, batching, metadata, reset, cursor resume, and reconnect policy. |
| sdks/…/streams.test.ts | Shows the client guarantees for cancellation, reconnect, producer sequencing, fallback, reset, metadata, and payload fetch errors. |
| sdks/…/streams.py | Shows Python publishing, batching, payload transfer, metadata, reset, cursor resume, and reconnect policy. |
| sdks/…/streams.ts | Shows core TypeScript durable publishing, batching, producer tracking, limits, and the separate run-scoped publishing API. |
| sdks/…/run.ts | Shows application publishing, consuming, cursor resume, cancellation, namespaces, and reset. |
| sdks/…/workflow.ts | Shows workflow publishing and reset behavior across task retries. |
| sdks/…/durable-streams.e2e.ts | Demonstrates replay, cursor resume, reset boundaries, namespace isolation, and metadata. |
| sdks/…/durable-streams-retry.e2e.ts | Demonstrates how live and late readers see different retry histories. |
| pkg/…/streams.go | Defines address, payload, cursor, and retained-message limits used by the service. |
| pkg/…/limits.go | Defines the default tenant topic, message-window, and retention settings. |