Skip to main content

Overview

The Stream API provides a real-time, key-value data store with automatic synchronization across workers. Unlike traditional databases, Stream data is organized into named streams with groups and items, making it ideal for collaborative applications, live dashboards, and multiplayer experiences.

Stream Structure

Hierarchy:
  • Stream: Named collection (e.g., “todos”, “users”, “messages”)
  • Group: Logical partition within stream (e.g., “inbox”, “team-1”, “room-42”)
  • Item: Individual record with unique ID and data
Streams are automatically created on first use. No schema definition required.

Stream Interface

The IStream<TData> interface defines operations:

Creating Streams

Custom Stream Implementation

Implement your own backend:

Registering Stream Functions

The SDK registers stream functions automatically:
Functions are named: stream::get(streamName), stream::set(streamName), etc.

Stream Operations

Get Item

Retrieve a single item by ID:
Type definition:

Set Item

Create or update an item:
Type definitions:

Delete Item

Remove an item:
Type definitions:

List Items in Group

Retrieve all items in a group:
Type definition:

List Groups

Retrieve all group IDs in a stream:
Type definition:

Partial Updates

Update specific fields without fetching the entire item:

Update Operations

Type definitions:

Set Field

Increment/Decrement

Remove Field

Merge Object

Multiple Operations

Update input type:

Real-World Example: Todo Application

Stream Helper Wrapper

Create a type-safe helper for specific streams:

Stream vs State

The III SDK provides both Stream and State APIs: State example:
Use Stream when you need grouping and listing. Use State for simple key-value storage.

Backend Implementation Notes

When implementing IStream:
1

Handle Nulls

Return null from get() when item doesn’t exist. Return null from update() if item doesn’t exist.
2

Atomic Updates

Implement update() atomically to prevent race conditions. Use database transactions or compare-and-swap.
3

Group Listing

listGroups() should return unique group IDs. Consider caching for large streams.
4

Serialization

Stream data is passed as JSON. Ensure your types serialize correctly.
5

Error Handling

Throw descriptive errors. The Engine will convert them to InvocationResult errors.

Multi-Language Support

Next Steps

Channels

Stream large binary data with channels

Functions

Call stream operations from functions