Streams
Append-only commit log with Stream IDs, consumer groups, partitioning, tiered storage, and blocking reads.
Flo streams are append-only, ordered logs of records backed by the Unified Append Log. Every append is Raft-replicated before being acknowledged. There is no separate stream projection — reading a stream is reading UAL entries directly, making it zero-copy and the fastest primitive.
Streams are the foundation of event sourcing, activity feeds, change data capture, and real-time data pipelines.
Core Concepts
Stream IDs
Every record in a stream is identified by a Stream ID — a composite <timestamp_ms>-<sequence> value:
- timestamp_ms: Unix milliseconds when the record was appended
- sequence: Counter within the same millisecond (0-indexed)
- Example:
1703350800000-0,1703350800000-1,1703350801000-0
Stream IDs are monotonically increasing. If the system clock goes backward, the previous timestamp is reused and the sequence increments — guaranteeing ordering without coordination.
Special values:
0-0— the very beginning of the stream$— the current tail (only future records)
Namespace Isolation
Streams live inside namespaces. The default namespace is used when no -n flag is provided. The same stream name in different namespaces is fully independent — separate records, separate consumer groups, separate metadata.
flo ns create staging
flo ns create production
flo stream append events '{"env":"staging"}' -n staging
flo stream append events '{"env":"prod"}' -n production
# Each namespace sees only its own records
flo stream read events --limit 10 -n staging
flo stream read events --limit 10 -n production
# Consumer groups are also namespace-scoped
flo stream group create events --group workers -n staging
flo stream group create events --group workers -n production
Partitioning
Streams can have multiple partitions for parallel throughput. When you create a stream with --partitions N, each partition is an independent ordered log.
# Create a 4-partition stream
flo stream create orders --partitions 4
Routing records to partitions:
- Explicit partition:
--partition 2sends to partition 2 directly - Partition key:
--partition-key alicehashes the key to a deterministic partition (Wyhash). All records with the same key land on the same partition, preserving per-key ordering. - No flag: defaults to partition 0
# Explicit partition
flo stream append orders '{"id":1}' --partition 2
# Partition key — all alice events on the same partition
flo stream append orders '{"user":"alice"}' --partition-key alice
flo stream append orders '{"user":"alice"}' --partition-key alice # same partition
# Different key may route to a different partition
flo stream append orders '{"user":"bob"}' --partition-key bob
Reading from partitions:
# Read only partition 1
flo stream read orders --partition 1
# Read using the same partition key (resolves to the same partition)
flo stream read orders --partition-key alice
# Bare read without --partition or --partition-key reads ALL partitions
flo stream read orders --limit 20
A bare stream read without partition flags returns records from all partitions merged together. This matches industry-standard behavior (Kafka, Redpanda, Pulsar).
Operations
Append
# Single record
flo stream append events '{"type":"signup","user":"alice"}'
# Batch append (multiple payloads in one request)
flo stream append events 'event-a' 'event-b' 'event-c'
# With headers
flo stream append events '{"type":"login"}' -H source=web -H trace-id=abc123
# To a specific partition
flo stream append events '{"type":"login"}' --partition 2
# With partition key routing
flo stream append events '{"type":"login"}' --partition-key alice
# JSON output (returns the Stream ID)
flo stream append events 'hello' --json
The response includes the assigned Stream ID (e.g., 1703350800000-0).
One append — all its records and headers together — takes at most 64 KiB and
1000 records. More records are refused with stream append: a batch of N records is over the limit of 1000; a value that isn't a well-formed batch is refused as
stream append: malformed batch.
Read
# From the beginning
flo stream read events --start 0-0 --limit 10
# From a specific Stream ID
flo stream read events --start 1703350800000-0 --limit 50
# Bounded range (inclusive on both ends)
flo stream read events --start 1703350800000-0 --end 1703350815000-0
# JSON output (includes id, payload, tier, partition fields)
flo stream read events --limit 10 --json
--limit counts records (default 10, at most 1000). A read never splits an
append: it returns the whole appends that fit the limit, and always at least
one, so a single append larger than the limit comes back entire. A range's
--end likewise returns the whole append it falls in. --start is exclusive
and may name any record, including one inside an append: the read resumes with
the record after it.
A read of a stream that doesn't exist, never created or since deleted, is
not found (exit 1). A stream that exists with nothing in the range, or
nothing past --start, answers no records and succeeds.
Blocking Reads
Blocking reads wait for new data instead of returning empty results immediately.
# Block up to 5 seconds for new records
flo stream read events --block 5000 --start 0-0 --limit 5
# The longest wait the server allows: 5 minutes (a longer one is refused;
# 0 does not wait)
flo stream read events --block 300000 --start 0-0 --limit 5
# Block for new records from the tail only (skip existing data)
flo stream read events --block 5000 --start '$' --limit 5
If matching data already exists, the blocking read returns immediately. If no data arrives within the timeout, it returns an empty (but successful) result. A blocking read of a stream that doesn't exist yet waits for its first append, rather than answering not found.
Follow Mode
Follow mode is a continuous tail — it keeps reading as new records arrive, like tail -f.
# Follow from the beginning (prints existing + new records)
flo stream read events --follow --start 0-0
# Follow from the tail (new records only)
flo stream read events --follow --start '$'
--follow implies a blocking timeout and loops internally. It runs until interrupted.
Create
Streams are auto-created on first append. Explicit creation is only needed when you want multiple partitions or custom retention up front.
flo stream create events # 1 partition (default)
flo stream create events --partitions 4 # 4 partitions
flo stream create events --retention 72 # 72-hour retention
A stream's partition count and retention are logged when it's created, so every node has them, and they survive a restart and a leader change.
Creating a stream that already exists answers ok if it asks for the same settings, as a retry does. If it asks for others, it's refused: conflict: the stream exists with other settings; change them with stream alter. A stream that exists only because something was appended to it has no settings yet, so a create sets them. Change retention with flo stream alter; altering a stream that has no settings is not_found. A stream's partition count is fixed when it's created.
Info
flo stream info events
flo stream info events --json
Returns stream metadata: name, partition count, first/last Stream IDs, record count.
List
flo stream ls
flo stream ls --limit 50 --json
Trim
Remove old records to reclaim storage.
# Keep only the last 10,000 records
flo stream trim events --maxlen 10000
# Remove records before a specific Stream ID
flo stream trim events --before 1703350800000-0
# Remove records older than 1 hour
flo stream trim events --maxage 3600
# Give exactly one of --before, --maxlen or --maxage; a zero bound is refused.
# Count what a trim would remove, removing nothing
flo stream trim events --maxlen 10000 --dry-run
Trim removes whole append batches. With --maxlen, it cuts at the last batch
boundary that removes no more than the excess, so a stream written in batches
may keep a few more than --maxlen records. The count printed, and the dry
run's count, is the number of records the trim removes.
Delete
Drop an entire stream — its records, metadata, and name registry. This is the symmetric counterpart to kv delete; use trim when you only want to remove records but keep the stream.
# Delete an empty stream (alias: flo stream rm)
flo stream delete events
# Force-delete a stream that still has records
flo stream delete events --force
Deleting a stream that does not exist is a no-op (idempotent), and the name can be reused immediately afterward. A non-empty stream is refused unless --force is passed. Consumer groups are scoped to their stream (see Consumer Groups), so deleting a stream also deletes that stream's groups; a same-named group on another stream is unaffected.
Consumer Groups
A consumer group lets several consumers share a stream: each record goes to one of them, leased to it until it acks. Delivery is at-least-once. A record whose lease runs out, or that is nacked, goes to the group's next read; one nacked or expired too often is dead. Every delivery, ack and lease is a log entry, so a restart or a new leader keeps them.
A group is scoped to a single stream: its identity is the (stream, group) pair. The same group name on two streams is two independent groups. A group read targets exactly one stream; wildcard reads are refused:
# ✗ refused — a group reads a single stream
flo stream group read "events.*" --group g --consumer w1
To process events of many types through one group, write them to a single stream with a type discriminator in the payload (e.g. a JSON "type" field) and branch with stream processing.
Reading
# Create a group (optional: the first read creates one at the defaults)
flo stream group create events --group processors --ack-timeout 60000 --max-deliver 5
# Read up to 10 records
flo stream group read events --group processors --consumer worker-1 --limit 10
A read takes the group's ready records first (nacked, or whose lease ran out), oldest first, then the stream's records past the group's cursor, one record at a time: a read may take part of a multi-record append. A read takes at most 100 records; a larger --limit reads 100. It prints each record with its delivery, term.index.id.deliveries:
3.42.1703350800000-0.1 {"type":"login","user":"ada"}
With --block <ms> a read waits for a record, up to 5 minutes.
Ack, nack and touch
Each takes the deliveries a read printed:
# Done with them: they leave the group
flo stream group ack events --group processors --consumer worker-1 --ids 3.42.1703350800000-0.1,3.42.1703350800000-1.1
# Failed: ready again after --delay, or dead now with --dlq
flo stream group nack events --group processors --consumer worker-1 --ids 3.42.1703350800000-0.1 --delay 10000 --error "upstream timed out"
# Never started, or a stop cut them short: ready again at once, no attempt spent
flo stream group nack events --group processors --consumer worker-1 --ids 3.42.1703350800000-0.1 --abandon
# Still working: with half the lease or less left, a full lease from now
flo stream group touch events --group processors --consumer worker-1 --ids 3.42.1703350800000-0.1
A nack's --error is kept on the record, up to 1024 bytes. --abandon hands records back unstarted, as a worker does with what it read but never began, or what a stop cut short: they're ready again at once, the delivery counted but no attempt spent. It takes no --delay, --dlq or --error, and it never dead-letters, so a worker that abandons on every error passes a poison record around for ever; nack those instead.
Acking one record of an append acks only that record. A report naming a delivery that has moved on applies nothing to that record and says why: acked already (gone), delivered again since, held by another consumer, or its lease ran out. Retrying an ack whose answer was lost is safe: the record answers gone. An ack, nack or touch to a group that isn't there is refused not_found as a whole.
Leases and attempts
- Lease (
--ack-timeout, default 30 s, 5 s to 12 h): a record not acked or touched that long goes to the group's next read, its deliveries counted. A new leader gives the leases its predecessor granted a grace of up to 30 s before ending them. - Attempts (
--max-deliver, default 5, 1 to 255): a record nacked or expired that many times is dead: it is kept, counted ininfo, and not delivered again until it is requeued. A dead record leaves when it is requeued or deleted, when its group is deleted, or when a stream trim passes it.
Both are set when the group is created. Creating it again with the same settings says it exists; with others, it is refused, naming the group's own.
Inspecting a group
# Records out to consumers now, oldest first
flo stream group pending events --group processors [--consumer worker-1]
# Ready, leased and dead counts, and the consumers holding records
flo stream group info events --group processors
A group's members are the consumers holding its records now; there is no join or leave.
Dead letters
# A group's dead letters, oldest dead first: deliveries, failures, when it died, its last error
flo stream group dlq list events --group processors [--limit 20] [--after <cursor>]
# Ready again at once, with their attempts reset
flo stream group dlq requeue events --group processors --ids 1703350800000-0,1703350800000-1
flo stream group dlq requeue events --group processors --all [--max 500]
# Gone for good: see what would go first
flo stream group dlq delete events --group processors --all --dry-run
flo stream group dlq delete events --group processors --all
A requeued record gets its full attempts again: its failures go to 0, while its deliveries and its last error stay, so its history still shows. It is ready at once and goes to the group's next read. A record a trim cut since it died can't be read again, so a requeue answers it gone; --all passes over those, which cleanup takes.
--all works a batch of up to 100 at a time, oldest first, each batch logged on its own; each is printed as it is answered, with any record it refused, so a run cut short shows how far it got. --max stops it after that many, no batch taking more than is left. A --dry-run looks at one batch, and says when more remain past it. A record named that isn't dead is refused not dead, and the command exits 3.
Stealing records
# Take records worker-1 holds and has left idle 5 minutes or more
flo stream group steal events --group processors --consumer rescue --min-idle 300000 \
--ids 3.42.1703350800000-0.1
A steal takes records another consumer holds: each gets a new delivery for --consumer, with the group's lease unless --lease names one, and its failures stay. It prints each record's new delivery, as a read does, and the old holder's ack, nack or touch is stale from then on.
Only a record idle at least --min-idle is taken. Idle is the time since its holder last touched it: its read, a steal, or any touch, even one that leaves the lease as it stands (a touch moves the lease only once half of it is gone). So a consumer that touches what it holds more often than --min-idle is alive and is never stolen from; one that stopped is. A record not idle long enough is refused not idle, and the command exits 3.
A steal is for an operator moving work off a consumer that hangs while holding its lease. It is never needed for recovery: a record whose lease runs out goes to the group's next read by itself.
Trims and deletes
A record a trim removes is never delivered again; info counts it in trimmed_pending alone until cleanup takes it, shortly after, so ready, leased, dead and trimmed_pending add up to what the group holds. Deleting a stream deletes its groups, and flo stream group delete deletes one: either is gone at once, and the group's records are cleaned up in the background. Until they are, creating or reading a group of that name answers still being removed; retry.
Limits
A group's records count against the [queues] caps: a group holds at most 100,000 records (ready, leased and dead) unless the caps say otherwise, and each counts 512 bytes and its error text toward the shard's total, which its queues and groups share. Past a cap, a read takes no new records; with none ready to go again, it is refused overloaded with reason group_held_full, naming the cap, and the CLI exits 4:
Error: overloaded: group 'processors' on stream 'events' is full: it holds 100000 records (at most 100000) and 51200000 held bytes (at most 268435456), leased, ready and dead; ack or nack the leased ones, and requeue or delete the dead ones (dlq) [overloaded/group_held_full]
Reading again won't help until room is made: leased records leave as consumers ack or nack them, dead ones when they are deleted, the group is deleted or a trim passes them, and the shard's total clears as its other groups and queues drain. So a consumer seeing group_held_full acks what it holds rather than retrying the read.
SDK Examples
client := flo.NewClient("localhost:9000")
client.Connect()
defer client.Close()
// Append
result, _ := client.Stream.Append("events", []byte(`{"event":"signup"}`), nil)
// Read from beginning
records, _ := client.Stream.Read("events", &flo.StreamReadOptions{
Start: &flo.StreamID{TimestampMS: 0, Sequence: 0},
Count: ptr(uint32(10)),
})
for _, rec := range records.Records {
fmt.Printf("id=%d-%d: %s\n", rec.ID.TimestampMS, rec.ID.Sequence, rec.Payload)
}
// Blocking read
records, _ = client.Stream.Read("events", &flo.StreamReadOptions{
Tail: true,
BlockMS: ptr(uint32(5000)),
Count: ptr(uint32(10)),
})
// Consumer group
records, _ = client.Stream.GroupRead("events", "processors", "worker-1",
&flo.StreamGroupReadOptions{
Count: ptr(uint32(10)),
BlockMS: ptr(uint32(30000)),
},
)
// ... process records ...
ids := make([]flo.StreamID, len(records.Records))
for i, rec := range records.Records {
ids[i] = rec.ID
}
client.Stream.GroupAck("events", "processors", ids, &flo.StreamGroupAckOptions{
Consumer: "worker-1",
})Reading Modes
| Mode | CLI Flag | Behavior |
|---|---|---|
| From beginning | --start 0-0 | Returns all records in order |
| From ID | --start <id> | Returns records starting at (or after) the given Stream ID |
| Range | --start <id> --end <id> | Bounded range, inclusive on both ends |
| Tail | --start '$' | Only records appended after the read begins |
| Blocking | --block <ms> | Waits up to <ms> for new data (at most 300000 ms, 5 minutes; 0 does not wait; a longer wait is refused) |
| Follow | --follow | Continuous tail — keeps reading as new records arrive |
| Partition | --partition <n> | Reads from a specific partition only |
| Partition key | --partition-key <key> | Reads from the partition that key hashes to |
| JSON output | --json | Machine-readable output with id, payload, tier, partition fields |
Tiered Storage
A record's payload is served from wherever it still is:
| Tier | Code | Where | Purpose |
|---|---|---|---|
| Hot | 0 | The in-memory ring buffer of recent appends | Recent writes, lowest latency |
| Warm | 1 | In-memory copies of recent payloads (the newest 32 MB per shard) | A record whose payload wraps the ring's end, or history when the ring is smaller than this store |
| Disk | 2 | The log on disk: its sealed segments, or the buffer of the segment being written | All the rest of the stream's history |
When you read with --json, each record includes a "tier" field saying where it was served from. The codes are the same in every SDK and in the wire protocol's tier byte.
Reads are transparent: the server merges results across tiers. A record read from disk is read off the request path, so a read answers with the records it already holds, in order, up to the first one still being read:
- A plain read answers at once with what it holds. One that holds none of its window waits up to its
block_ms, and at most 2 seconds; a local disk read takes milliseconds, and the bound is for a failing disk. If the records aren't back in time, it is refusedunavailablewithran= no, never answered short. The SDKs retry it. - A consumer group read delivers only the records its reply carries; the rest stay where they were. One that holds none of its window is refused
unavailablewithran= no at once, with nothing delivered, and its retry finds the records read. Resending it is always safe. - A read that can't be made right now (a resource shortage, or an IO error) is refused
unavailablewithran= no at once, saying why.
If the log on disk turns out to be damaged (a sealed segment that's corrupt, or that doesn't hold a committed record), that's damage to the shard, as when the server starts or applies: a lone node takes the shard offline, and a cluster member stops taking part in its group. It shows in /status, and reads held on the shard are refused with it. An IO error that lasts five minutes is treated the same way; a permission error says so. See Durability and the diverged state for what an operator does next.
The hot ring's size is configurable per server (hot buffer capacity, max hot entries).
Durability
- All appends are Raft-replicated before acknowledgment
- Stream data survives server restarts, and so does each consumer group: its ack floor and its config, whether
group createor a firstgroup readmade it - A group's pending list does not survive a restart yet. Recovery is at-least-once: the group resumes from its ack floor, so records delivered but not acked are delivered again, and acked records are skipped
- Replay is deterministic — Stream IDs are anchored to the originating entry timestamp, so a record keeps the same ID when rebuilt from the log
- After restart, new appends continue with monotonically increasing Stream IDs (no duplicates, no gaps)
- Immediate consistency — a read right after restart returns all pre-restart data
How It Works
Stream records are UAL entries with opcode = stream_append. Reading a stream is reading a range of UAL entries filtered by stream name hash — there is no separate data structure.
- Record IDs are derived from append wall-clock time plus sequence
- Zero-copy reads — no derived state, no projection overhead
- Consumer group state (cursors, PEL, mode) is managed per-shard
- Partition routing uses Wyhash on the partition key or explicit index
- Blocking reads register waiters that are notified on append
See Storage Internals for details.