Stream
Ordered, replayable events for messages, orders and AI output, with cursors, retention, gaps and idempotent retries.
A stream event is kept in order with every other stream event in its topic, for a bounded time, so a subscriber can replay what it missed. It is the default type, and the right one whenever a user would be upset to miss an event.
Use it for: chat messages, comments, orders and status changes, notifications, AI output that must survive a page reload.
How it behaves
- Ordered. Each stream event gets the next position in its topic,
(epoch, seq), and every subscriber sees the same order. - Replayable. A subscriber picks where to start: only new events, the oldest still retained, the last N, or after a cursor it saved. It gets the replay, then live events, with nothing missed or repeated at the seam.
- Bounded. A topic keeps stream events up to its rule's byte cap (5 MiB by default) and at most 24 hours; the oldest go first.
- Retried safely. Every stream publish carries an idempotency key. Retrying with the same key within 10 minutes doesn't deliver it twice.
- Permanent IDs. Each event gets a uid that never changes. Point replies, edits and receipts at it.
Positions and gaps
Save the cursor of the last event you processed. After a reconnect or a reload, subscribe after it to catch up. If the events after your cursor are gone, you get a gap first, with the oldest position still available.
Delivery and ordering covers cursors, gaps and idempotency in full.
Not a database
Stream history is short and may not survive a restart of the service. Keep the record of truth, the full chat history or the order log, in your own database, and use the stream to deliver it live and fill short gaps. A common pattern: your backend writes to its database, then publishes the event.
Rule settings
| Setting | Default | Meaning |
|---|---|---|
| Retention (bytes) | 5 MiB | How much history each topic keeps |
| Payload limit | Segment's limit, at most 60 KiB | Largest event |
In code
const room = client.topic('rooms/42');
room.subscribe((msg) => render(msg), { from: { last: 50 } });
const receipt = await room.publish('message', { text: 'Hi!' });See Publishing and Subscribing.