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 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
modules::stream::adapters::RedisAdapter
Uses Redis as the backend for the streams. Stores stream data in Redis and leverages Redis Pub/Sub for real-time event delivery.Configuration
modules::stream::adapters::KvStore
Built-in key-value store. Supports in-memory or file-based persistence. No external dependencies required.Configuration
Functions
Sets a value in the stream.
Parameters
Parameters
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
Atomically update an item in the stream using a list of operations.
Parameters
Parameters
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 module 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: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:
Function ID for conditional execution. The engine invokes it with the event payload; if it returns
false, the handler function is not called.Sample Code
- 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 module 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