Architecture
Data Flow
When a worker triggersstream::set, the engine:
- Persists the data via the configured adapter (Redis or KvStore)
- Publishes a notification to all WebSocket clients subscribed to that stream and group
- Evaluates registered
streamtriggers and fires matching handlers
stream::set handles persistence, real-time delivery, and reactive logic in one operation.
Groups
Streams organize data hierarchically:stream_name > group_id > item_id.
- stream_name identifies the top-level stream (e.g.
chat,presence,dashboard) - group_id partitions data within a stream (e.g.
room-1,team-alpha) - item_id uniquely identifies a record within a group (e.g.
user-123,msg-456)
ws://host:port/stream/{stream_name}/{group_id}/. They receive all item-level changes within that group.
Sample Configuration
Configuration
The port to listen on. Defaults to
3112.The host to listen on. Defaults to
0.0.0.0.The authentication function to use. It’s a path to a function that will be used to authenticate the client. You can
register the function using the iii SDK and then use the path to the function here.
The adapter to use. It’s the adapter that will be used to store the streams. You can register the adapter using the
iii SDK and then use the path to the adapter here.
Adapters
redis
Uses Redis as the backend for the streams. Stores stream data in Redis and leverages Redis Pub/Sub for real-time event delivery.Configuration
The URL of the Redis instance to use.
kv
Built-in key-value store. Supports in-memory or file-based persistence. No external dependencies required.Configuration
Storage method. Options:
in_memory (lost on restart) or file_based (persisted to disk).Directory path for file-based storage. Each stream is stored as a separate file.
Functions
Sets a value in the stream.
Parameters
Parameters
Gets a value from the stream.
Deletes a value from the stream.
Retrieves a group from the stream. This function will return all the items in the group.
Send a custom event to all subscribers of a stream group.
Parameters
Parameters
The ID of the stream to send the event to.
The group ID in the stream to send the event to.
The event type string delivered to subscribers.
Optional item ID to associate the event with.
The event payload delivered to subscribers.
Returns
Returns
Returns
null on success.Atomically update an item in the stream using a list of operations.
Parameters
Parameters
The ID of the stream containing the item to update.
The group ID in the stream containing the item to update.
The item ID in the stream to update.
The list of atomic operations to apply. Each operation is a tagged object with a
type field (set, merge, increment, decrement, append, or remove) and associated fields (path, value, by). For set / increment / decrement / append / remove, paths are first-level field names. For merge, path accepts either a single string (legacy / first-level field) or an array of literal segments for nested merge — see the state worker docs for the full contract and validation rules. Use path: "" (or omit path) to target the root value.Returns
Returns
Error codes
stream::update uses the same update engine as state::update. Each op may add an entry to the response errors array. Operations are best-effort: successfully applied ops still reflect in new_value, and failed ops are skipped.
Each error includes
op_index, code, and message; doc_url is optional.
Authentication
It’s possible to implement a function to handle authentication.- Define a function to handle the authentication. It received one single argument with the request data.
- Node / TypeScript
- Python
- Rust
- Make sure you add the function to the configuration file.
- Now whenever someone opens a websocket connection, the function
onAuthwill be called with the request data.
Trigger Types
This worker adds three trigger types:stream (item changes), stream:join (WebSocket connect), and stream:leave (WebSocket disconnect).
stream:join and stream:leave
Fire when a client connects or disconnects via WebSocket. Both trigger types deliver the same payload to the handler:The subscription ID, used for uniqueness and logging.
The stream name of the subscription.
The group ID of the subscription.
The item ID of the subscription, if provided by the client.
The context generated by the authentication layer.
- Node / TypeScript
- Python
- Rust
stream
Fires when an item changes in the stream (viastream::set, stream::update, or stream::delete). Register with a config object to filter which stream, group, or item triggers the handler:
The stream name to watch. Only changes on this stream fire the handler.
If set, only changes within this group fire the handler.
If set, only changes to this specific item fire the handler.
Function ID for conditional execution. The engine invokes it with the event payload; if it returns
false, the handler function is not called.The event type:
create, update, or delete.Unix timestamp of the event.
The stream where the change occurred.
The group where the change occurred.
The item ID that changed.
The event detail object containing
type and data fields.- Node / TypeScript
- Python
- Rust
Usage Example: Real-Time Presence
Streams organize data bystream_name, group_id, and item_id. Use for live presence, collaborative docs, or dashboards:
- Node / TypeScript
- Python
- Rust
ws://host:3112/stream/presence/room-1/ and receive real-time updates when items change.
Usage Example: Join with Auth Context
Configure the stream worker with an auth function:Authorization: Bearer <token> (Node.js) or Sec-WebSocket-Protocol: Authorization,<token> (browser stream-client):
- Node / TypeScript
- Python
- Rust
context:
- Node / TypeScript
- Python
- Rust
Usage Example: Conditional Join
- Node / TypeScript
- Python
- Rust