GET /streams//records (Streaming)
Establish a long-lived streaming session to continuously read records from a stream. This endpoint supports two streaming protocols: Server-Sent Events (SSE) and S2S.When to Use Streaming
Use streaming reads when you need to:- Tail a stream in real-time
- Process records continuously as they arrive
- Read large volumes of data without pagination
- Maintain a live connection with automatic reconnection
Authentication
Requires a valid access token with read permissions to the stream.Path Parameters
Stream name to read records from.
Headers
Basin name where the stream resides.
Encoding format for SSE streaming:
base64- Base64-encoded binary data (default)utf8- UTF-8 text
Streaming protocol:
text/event-stream- Server-Sent Eventss2s/proto- S2S binary protocol
For SSE reconnection. Automatically set by browsers when reconnecting.Format:
{seq_num}:{count}:{bytes}Example: "42:10:8192" resumes from seq_num 43 with 10 records and 8192 bytes already consumed.For S2S protocol, request compression:
zstd- Zstandard compression (preferred)gzip- Gzip compression
Query Parameters
Same as Read Records with these differences:countandbyteshave no default limits (can stream indefinitely)waitdefaults to infinite (connection stays open)waitacts as an idle timeout - connection closes if no records arrive within this duration
Server-Sent Events (SSE)
Event Types
Contains a batch of records.
- id:
{seq_num}:{count}:{bytes}- Resume token for reconnection - data: JSON object with
recordsarray and optionaltail
Heartbeat event sent when switching to real-time tail following or during idle periods (every 5-15 seconds).
- id: Last known position
- data: Empty
End of stream event. Sent when all requested records have been delivered.
- data: Empty
Error event terminates the stream.
- data: JSON error details
Examples
Stream from tail with SSE
Stream historical records then tail
Reconnection with Last-Event-ID
Stream with time bound
done event.
S2S Protocol
The S2S (S2 Streaming) protocol is a high-performance binary streaming format using length-prefixed protobuf frames.Frame Format
- Bit 7: Terminal flag (1 = terminal message, 0 = regular)
- Bits 6-5: Compression algorithm (00 = none, 01 = zstd, 10 = gzip)
- Bits 4-0: Reserved (must be 0)
- Regular frame: Protobuf
ReadBatchmessage (optionally compressed) - Terminal frame: 2-byte status code + JSON error body
Regular Frame
Contains aReadBatch protobuf message:
Heartbeat Frames
Emptyrecords array with tail set indicates a heartbeat:
Terminal Frame
Terminates the stream with an error or normal completion:Compression
Payloads over 1 KiB are automatically compressed ifAccept-Encoding is specified:
zstd- Zstandard (preferred, better compression ratio)gzip- Gzip (widely supported)
Examples
S2S stream from tail
Python S2S client example
Session Behavior
Historical Catch-up
When starting before the tail, the session reads historical records in batches:- Batches contain up to 1000 records or 1 MiB (whichever is reached first)
- Batches are delivered as fast as the client can consume them
- No heartbeats during historical catch-up
Real-time Tail Following
Once caught up to the tail:- A heartbeat is sent to signal the transition
- New records are streamed as they arrive
- Heartbeats sent every 5-15 seconds if idle
- Connection remains open until client closes or
waittimeout expires
Bounds and Termination
The session terminates with adone event when:
countlimit is reachedbyteslimit is reacheduntiltimestamp is encounteredwaittimeout expires with no new records
count, bytes, or until), the session continues indefinitely.
Error Handling
SSE Reconnection
Browsers automatically reconnect on connection loss. SetLast-Event-ID header with the last received event ID to resume:
S2S Reconnection
Clients must implement reconnection logic:- Track the last successfully processed
seq_num - On reconnection, set
seq_num={last_seq_num + 1}in query params - Adjust
countandbyteslimits to account for already-received records
Common Errors
- 408 Request Timeout:
waittimeout expired, reconnect to continue - 416 Range Not Satisfiable: Starting position beyond tail (check
tailin error response) - 503 Service Unavailable: Temporary backend issue, retry with backoff
Performance Considerations
- SSE: Lower throughput due to JSON overhead, but simpler integration and automatic reconnection
- S2S: Maximum throughput with binary protobuf and compression, requires custom client
- Historical catch-up is bandwidth-limited by storage backend (~100-500 MB/s typical)
- Real-time streaming latency is typically < 10ms from append to delivery
- Use compression for payloads > 1 KiB to reduce bandwidth
Notes
- SSE connections have a default max age of 45 seconds before requiring reconnection (configurable)
- S2S streams continue until explicitly terminated or error occurs
- Heartbeats prevent connection timeout and confirm session health
- Empty batches (heartbeats) update the
tailposition but contain no records - For fan-out scenarios, consider using multiple streams instead of multiple readers on one stream