Skip to main content
Durable streams for real-time data subscriptions.

Architecture

Data Flow

When a worker triggers stream::set, the engine:
  1. Persists the data via the configured adapter (Redis or KvStore)
  2. Publishes a notification to all WebSocket clients subscribed to that stream and group
  3. Evaluates registered stream triggers and fires matching handlers
A single 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)
Clients subscribe at the group level by connecting to 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

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

string
The URL of the Redis instance to use.

modules::stream::adapters::KvStore

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.
string
required
The ID of the stream to set the value in.
string
required
The group ID of the stream to set the value in.
string
required
The item ID of the stream to set the value in.
any
required
The value to set in the stream.
any
The previous value, or null if the item was newly created.
any
required
The value now stored in the stream.
function
Gets a value from the stream.
string
required
The ID of the stream to retrieve the value from.
string
required
The group ID in the stream to retrieve the value from.
string
required
The item ID in the stream to retrieve.
any
required
The value retrieved from the stream.
function
Deletes a value from the stream.
string
required
The ID of the stream to delete the value from.
string
required
The group ID in the stream to delete the value from.
string
required
The item ID in the stream to delete.
any
The value that was deleted, or null if the item did not exist.
function
Retrieves a group from the stream. This function will return all the items in the group.
string
required
The ID of the stream to retrieve the group from.
string
required
The group ID in the stream to retrieve the group from.
any[]
required
The group retrieved from the stream. It’s an array of items in the group.
function
List all groups in a stream.
string
required
The ID of the stream to list groups from.
string[]
required
An array of group IDs in the stream.
function
List all streams with their group metadata.
This function takes no parameters.
object[]
required
An array of stream metadata objects. Each object has an id (string) and a groups (string[]) field.
number
required
The total number of streams.
function
Send a custom event to all subscribers of a stream group.
string
required
The ID of the stream to send the event to.
string
required
The group ID in the stream to send the event to.
string
required
The event type string delivered to subscribers.
string
Optional item ID to associate the event with.
any
required
The event payload delivered to subscribers.
null
Returns null on success.
function
Atomically update an item in the stream using a list of operations.
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, or remove) and associated fields (path, value, by).
any
The previous value, or null if the item was newly created.
any
required
The value now stored in the stream after applying the operations.

Authentication

It’s possible to implement a function to handle authentication.
  1. Define a function to handle the authentication. It received one single argument with the request data.
  1. Make sure you add the function to the configuration file.
  1. Now whenever someone opens a websocket connection, the function onAuth will 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:
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.

stream

Fires when an item changes in the stream (via stream::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.

Sample Code

Usage Example: Real-Time Presence

Streams organize data by stream_name, group_id, and item_id. Use for live presence, collaborative docs, or dashboards:
Clients connect via WebSocket to 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:
Register the auth function. Clients may send the token via Authorization: Bearer <token> (Node.js) or Sec-WebSocket-Protocol: Authorization,<token> (browser stream-client):
Join/leave triggers receive the auth context:

Usage Example: Conditional Join