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
TheIStream<TData> interface defines operations:
Creating Streams
Custom Stream Implementation
Implement your own backend:Registering Stream Functions
The SDK registers stream functions automatically:stream::get(streamName), stream::set(streamName), etc.
Stream Operations
Get Item
Retrieve a single item by ID:Set Item
Create or update an item:Delete Item
Remove an item:List Items in Group
Retrieve all items in a group:List Groups
Retrieve all group IDs in a stream:Partial Updates
Update specific fields without fetching the entire item:Update Operations
Set Field
Increment/Decrement
Remove Field
Merge Object
Multiple Operations
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:
Backend Implementation Notes
When implementingIStream:
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
- TypeScript
- Python
- Rust
Next Steps
Channels
Stream large binary data with channels
Functions
Call stream operations from functions