Skip to main content
Records are the fundamental units of data in S2 streams. The CLI provides commands for appending, reading, and tailing records.

Append records

Append records to a stream from stdin:
Output:
This shows:
  • Sequence number range appended: 0..0 (single record)
  • New tail position: sequence 1, timestamp 1704067200000

Append from a file

Or using shell redirection:

Append multiple records

Records are newline-delimited by default:
Output:

Append JSON records

Use the --format json flag for JSON records:
JSON records are still newline-delimited (one JSON object per line).

Append JSON with base64 bodies

Use --format json-base64 when record bodies contain binary data:

Append with fencing token

Enforce a fencing token to coordinate writers:
This append will be rejected if the stream’s current fencing token doesn’t match.

Append with sequence number match

Only append if the next sequence number matches the expected value:
This is useful for ensuring no records were appended by another writer.

Control batching with linger

Adjust how long to wait before flushing a batch:
Default: 5ms Lower values reduce latency but may increase number of API calls. Higher values improve throughput for bulk appends.

Read records

Read all records from a stream:
Output:
By default, read will tail the stream indefinitely, waiting for new records. Use --count or press Ctrl+C to stop.

Read a specific number of records

Reads the first 100 records and exits.

Read from a specific sequence number

Starts reading from sequence number 1000 (inclusive).

Read from a timestamp

Read records from a specific Unix timestamp (milliseconds):
Or use a human-friendly relative time:

Read the last N records

Read starting from N records before the tail:
Reads the last 100 records.

Limit by bytes

Stop reading after consuming a certain number of bytes:

Read until a timestamp

Read records up to (but not including) a specific timestamp:

Clamp start position at tail

If the requested start position is beyond the tail, start at the tail instead of returning an error:

Output to a file

Or using shell redirection:

Read formats

Text format (default):
Outputs raw record bodies, one per line. JSON format:
Outputs records as JSON objects with metadata:
JSON with base64 bodies:
Outputs records with base64-encoded bodies:

Tail a stream

Show the last N records (like Unix tail):
Default: Shows last 10 records and exits.

Specify number of records

Follow mode

Continuously show new records (like tail -f):
Press Ctrl+C to stop following.

Tail output formats

Same format options as read:

Common workflows

Stream processing pipeline

Export records to file

Continuous monitoring

Bulk import from file

Replay records to different stream

Coordinated append with fencing

Incremental backup

Appending command records

Certain operations like trim and fence append special command records to the stream. When reading with --format text, these are displayed as:
These command records are not included in the record body output.

Performance tips

Batching

  • Use --linger to control batch size vs. latency tradeoff
  • Larger batches (higher linger) improve throughput
  • Smaller batches (lower linger) reduce latency

Reading

  • Use --count or --bytes to limit reads
  • Filter records early in the pipeline to reduce data transfer
  • Use --format text for better performance if metadata isn’t needed

Network usage

Enable compression in your CLI configuration:

Examples

Append timestamped events

Read and count records

Tail with filtering

Read records from specific hour