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
number
The port to listen on. Defaults to
3112.string
The host to listen on. Defaults to
0.0.0.0.string
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.
Adapter
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
string
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
string
Storage method. Options:
in_memory (lost on restart) or file_based (persisted to disk).string
Directory path for file-based storage. Each stream is stored as a separate file.
Functions
function
Sets a value in the stream.
Parameters
Parameters
function
function
function
Retrieves a group from the stream. This function will return all the items in the group.
function
function
function
Send a custom event to all subscribers of a stream group.
Parameters
Parameters
Returns
Returns
null
Returns
null on success.function
Atomically update an item in the stream using a list of operations.
Parameters
Parameters
string
required
The ID of the stream containing the item to update.
string
required
The group ID in the stream containing the item to update.
string
required
The item ID in the stream to update.
UpdateOp[]
required
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.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:string
required
The subscription ID, used for uniqueness and logging.
string
required
The stream name of the subscription.
string
required
The group ID of the subscription.
string
The item ID of the subscription, if provided by the client.
object
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:
string
required
The stream name to watch. Only changes on this stream fire the handler.
string
If set, only changes within this group fire the handler.
string
If set, only changes to this specific item fire the handler.
string
Function ID for conditional execution. The engine invokes it with the event payload; if it returns
false, the handler function is not called.string
required
The event type:
create, update, or delete.number
required
Unix timestamp of the event.
string
required
The stream where the change occurred.
string
required
The group where the change occurred.
string
The item ID that changed.
object
required
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