Records
The routes that append, read, follow, trim, and fence the records of one stream.
The records routes write records to the end of a stream, read them back, and
control who may write and what stays readable. Each route is also a method of
the gRPC service nova.v1.DataPlaneService, and this page gives both.
Appends
Batches, acknowledgements, and retries
Reads
Where a read starts and when it stops
Append records with an SDK
Producers and one-shot appends in Go and TypeScript
Record commands
The same operations from the nova CLI
| Operation | HTTP | gRPC |
|---|---|---|
| Append | POST /v1/streams/{bucket}/{key}/records | Append, AppendSession |
| Read | GET /v1/streams/{bucket}/{key}/records | Read |
| Check the tail | GET /v1/streams/{bucket}/{key}/records/tail | CheckTail |
| Subscribe | GET /v1/streams/{bucket}/{key}/records/subscribe | Subscribe |
| Trim | POST /v1/streams/{bucket}/{key}/trim | Trim |
| Fence | POST /v1/streams/{bucket}/{key}/fence | Fence |
| Read plan | None | ReadPlan |
Every route names the stream in its path. The examples use the Gateway of the
local cluster from the quickstart at localhost:8080, and
the stream demo/events.
| Path parameter | Meaning |
|---|---|
bucket | The stream's bucket |
key | The stream's key, as one percent-encoded path segment: orders/eu is orders%2Feu |
Records and positions
A position is a point in a stream: a sequence number and the time of the record there. A record has a position, a body, and optional headers.
{
"seq_num": 1,
"timestamp_ms": 1795359513291
}{
"seq_num": 1,
"timestamp_ms": 1795359513291,
"body": "world",
"headers": [
{
"name": "content-type",
"value": "text/plain"
}
]
}| Field | Type | Meaning |
|---|---|---|
seq_num | integer | The record's sequence number. At an end or a tail, one past the last record |
timestamp_ms | integer | Unix milliseconds. At an end or a tail, the last record's time, or 0 when none is known |
body, body_b64 | string | The body, as text or as base64. Bodies and bytes says which one you get |
headers | array | {name, value} pairs, in order. Absent when the record has none |
range | string | On a scalable stream only: the range that holds the record |
A bookmark is the place to resume a read, returned by every read, tail, and
subscription event. On a plain stream it is the next sequence number as text,
such as "3". On a scalable stream it is an opaque string.
Over gRPC, Position has seq_num (uint64) and timestamp_ms (int64).
Record has seq_num, timestamp_ms, body (bytes), and headers. A
Header has name and value, both bytes. Header names are not empty, and a
name can repeat. A record's size is its body plus every header name and value.
Keep a record to 64 headers. gRPC and the Gateway take no more, and the SDKs refuse more before they send; Limits says where up to 100 pass.
Append records
POST /v1/streams/{bucket}/{key}/recordsgRPC: DataPlaneService.Append for one batch, AppendSession for a
session. Appends one batch to the tail of the stream, all
or nothing, and returns where it landed.
curl -s localhost:8080/v1/streams/demo/events/records -d '{
"records": [
{
"body": "hello"
},
{
"body": "world",
"headers": [
{
"name": "content-type",
"value": "text/plain"
}
]
}
]
}'{
"start": {
"seq_num": 0,
"timestamp_ms": 1795359513291
},
"end": {
"seq_num": 2,
"timestamp_ms": 1795359513291
},
"tail": {
"seq_num": 2,
"timestamp_ms": 1795359513291
}
}start is the first record's position and end is one past the last, so
this batch holds records 0 and 1. tail is where the stream ends after the
append. It is past end when other writers appended at the same time.
With match_seq_num, the append succeeds only at that position. Here the
stream already ends at 3, so the second try appends nothing:
curl -s localhost:8080/v1/streams/demo/events/records -d '{
"records": [
{
"body": "third"
}
],
"match_seq_num": 2
}'{
"error": "writer: append at 2, expected 3",
"tail": {
"seq_num": 3,
"timestamp_ms": 1795359513525
}
}| Status | When | Retry |
|---|---|---|
| 400 | The body is malformed: no records, both or neither of body and body_b64, a key named twice, or bad base64. Also a timestamp_ms the stream's timestamping mode refuses | No. Fix the request |
| 400 | One record holds more than 1 MiB of body and headers. Nothing was appended | No. Store a larger payload in object storage and append a pointer to it |
400 with reason: batch_too_large | More than 1,000 records, or more than 1 MiB of content in all | No. Split the batch |
| 400 | On a node's data bridge, a record with more than 100 headers | No. Send at most 64 headers |
| 404 | The bucket or stream does not exist, and the bucket does not create streams on append | After you create it |
412 with tail | match_seq_num is not the stream's next sequence number. Nothing was appended | With tail.seq_num, once you know your records are not already there |
412 with fencing_token | fencing_token does not match the installed token, or the stream is fenced and you sent none | Only with the token the body names, if you mean to take over |
| 413 | The body is over about 6.3 MiB, or one record's JSON is over about 1.36 MiB | No. Send fewer records, or the body as body_b64 |
| 429 | The node or the Gateway is short of capacity. retry_after_ms says when to try again | Yes, after retry_after_ms |
| 500 | Through the Gateway, a record with more than 64 headers | No. Send at most 64 headers |
| 503 | The stream's leader is moving, the node is draining, or another writer holds a fenced stream, which takes one writer at a time | Yes, after Retry-After |
Statuses every route shares are on API › Errors. Nova ignores body keys it does not know.
A plain append is not idempotent, so a retry can append the batch twice. When a
request fails after you sent it, through a timeout, a 503, or a dropped
connection, Nova may already have stored the batch. To make the retry safe,
send match_seq_num: if Nova stored the first try, the retry fails with 412.
Without it, check the tail and read from your last known
position before you resend.
Over gRPC, bodies and headers are raw bytes. A batch over the bound fails with
InvalidArgument and a BatchTooLarge detail that names the node's limits. A
message over one batch plus 1 MiB (2 MiB by default) fails with
ResourceExhausted before the node reads it. A match_seq_num miss is
OutOfRange with a Sequence detail, and a token mismatch is
FailedPrecondition with a Fence detail. A node that does not lead the
stream answers FailedPrecondition with a NotOwner detail: dial its
holder_addr and send again.
On a scalable stream, give each record its routing key in a
nova-routing-key header. Nova cuts the batch into one part per range, and the
response lists them in parts, each with its range, the indexes of its
records, and its positions. When the records reach more than one range, the
top-level positions are zero. If some parts fail, the status is the first
failure's, reason is partial_append, and parts says which records landed.
Sessions
A producer session sends many batches through one open request and gets
an acknowledgement for each, in order. It is how the SDKs append at high
throughput: over gRPC the bidirectional stream AppendSession, and over HTTP
this route with Content-Type: application/vnd.nova.session. A session may
hold up to its session window of unacknowledged batches, 48 MiB on
Standard and 8 MiB on Express and at most 1,024 batches, and past it the
producer waits. A failure ends the session: open a new one and resend the
unacknowledged batches in order. A plain batch can be stored twice this way;
a batch with match_seq_num cannot. Producer sessions
documents the messages, the rules, and the HTTP frames.
Read records
GET /v1/streams/{bucket}/{key}/recordsgRPC: DataPlaneService.Read. Returns one page of records at once, possibly
empty. A read never waits for new records; subscribe to wait.
Where the read starts. Send exactly one:
| Query | Type | Meaning |
|---|---|---|
from | string | beginning for the first record still stored, tail for only what comes next, or a bookmark |
seq_num | integer | The record with this sequence number |
timestamp_ms | integer | The first record stamped at or after this time |
tail_offset | integer | This many records before the tail |
When it stops, at whichever comes first:
| Query | Type | Default | Meaning |
|---|---|---|---|
limit | integer | 8,192 | The most records. A larger value is cut to the node's limit, 8,192 by default |
max_bytes | integer | 8 MiB | The most content bytes, cut to the node's limit, 8 MiB by default. One record always returns, however large |
until_ms | integer | None | Stop before the first record stamped at or after this time |
How the answer looks:
| Query | Type | Default | Meaning |
|---|---|---|---|
clamp | boolean | false | Start a read below the trim watermark at the first stored record. Without it, such a read fails with 410 |
format | string | raw | raw or base64. See Bodies and bytes |
curl -s 'localhost:8080/v1/streams/demo/events/records?seq_num=0&limit=2'{
"records": [
{
"seq_num": 0,
"timestamp_ms": 1795359513291,
"body": "hello"
},
{
"seq_num": 1,
"timestamp_ms": 1795359513291,
"body": "world",
"headers": [
{
"name": "content-type",
"value": "text/plain"
}
]
}
],
"bookmark": "2",
"tail": {
"seq_num": 3,
"timestamp_ms": 1795359513525
}
}The answer holds records, the bookmark after them, and the stream's tail.
To read the next page, send from=2, the bookmark, or seq_num=2. A scalable
stream's answer has no tail.
| Status | When | Retry |
|---|---|---|
| 400 | No start, two starts, a bad number, or an unknown format. With reason: position_per_range, a seq_num or tail_offset on a scalable stream | No. On a scalable stream, start from a bookmark, beginning, tail, or a time |
| 404 | The stream does not exist, and the bucket does not create streams on read | After you create it |
| 410 | The start is below the trim watermark | With from=beginning or clamp=true |
| 503 | The node cannot serve the stream right now | Yes, after Retry-After |
A page ends only where you bounded it or at the tail. So a page with fewer than
limit records, under max_bytes, and with no until_ms, reached the tail. A
start at or past the tail returns no records, and its bookmark is the tail.
Over gRPC there is no from and no bookmark: read from the beginning with
seq_num: 0 and clamp: true, and from the tail with tail_offset: 0.
Check the tail
GET /v1/streams/{bucket}/{key}/records/tailgRPC: DataPlaneService.CheckTail. Returns where the stream ends now. It takes
no parameters.
curl -s localhost:8080/v1/streams/demo/events/records/tail{
"bookmark": "3",
"tail": {
"seq_num": 3,
"timestamp_ms": 1795359513525
}
}tail.seq_num is the sequence number the next record will get, 0 for a new
stream. tail.timestamp_ms is the last record's time, or 0 when none is
known. The stream's leader answers, so the tail includes every acknowledged
append. When no node leads the stream, any node answers from stored state. A
scalable stream has no single tail and answers only a bookmark.
| Status | When | Retry |
|---|---|---|
| 404 | The stream does not exist. Checking the tail never creates one | After you create it |
| 503 | The leader is moving or the node is draining | Yes, after Retry-After |
Over gRPC, a node that does not lead the stream answers FailedPrecondition
with NotOwner.
Subscribe
GET /v1/streams/{bucket}/{key}/records/subscribegRPC: DataPlaneService.Subscribe, a server stream. Sends the records from a
start, then waits at the tail and sends each new batch once it is
acknowledged. It does not end on its own.
| Parameter | In | Meaning |
|---|---|---|
Last-Event-ID | Header | Resume after the last event you received. It wins over the query |
from, seq_num, timestamp_ms, tail_offset | Query | Where to start, as on read. One is required without Last-Event-ID |
format | Query | raw or base64 |
curl -N 'localhost:8080/v1/streams/demo/events/records/subscribe?seq_num=2'id: 3
data: {"records":[{"seq_num":2,"timestamp_ms":1795359513525,"body":"third"}],"bookmark":"3","tail":{"seq_num":3,"timestamp_ms":1795359513525}}
id: 4
data: {"records":[{"seq_num":3,"timestamp_ms":1795359515344,"body":"live"}],"bookmark":"4","tail":{"seq_num":4,"timestamp_ms":1795359515344}}
: hbEach event is one batch, sent as one data: line. Its data has the shape of
a read's answer, and its id is the bookmark after the batch. The first
event's data, formatted:
{
"records": [
{
"seq_num": 2,
"timestamp_ms": 1795359513525,
"body": "third"
}
],
"bookmark": "3",
"tail": {
"seq_num": 3,
"timestamp_ms": 1795359513525
}
}To resume after a disconnect, send the id of the last event you handled.
Here the client had handled only the first event:
curl -N -H 'Last-Event-ID: 3' localhost:8080/v1/streams/demo/events/records/subscribeid: 4
data: {"records":[{"seq_num":3,"timestamp_ms":1795359515344,"body":"live"}],"bookmark":"4","tail":{"seq_num":4,"timestamp_ms":1795359515344}}Heartbeats, expiring tokens, and connection limits are on Protocol ›
Server-sent events. Nova resolves a timestamp_ms start once,
when the subscription opens. Like a read, a subscription creates a missing
stream when its bucket creates streams on read.
| Status | When | Retry |
|---|---|---|
| 400 | No start, or a Last-Event-ID that is not a bookmark | No |
| 404 | The stream does not exist, and the bucket does not create streams on read | After you create it |
| 503 | The host is at its limit of long-lived connections, 4,096 by default | Yes, after Retry-After |
A start below the trim watermark
Over HTTP, a subscription that starts below the watermark answers 200 and then
ends without an event. Over gRPC it fails with OutOfRange. Start from
from=beginning when older records may have been trimmed.
Over gRPC, the start is seq_num or timestamp_ms. A node at its
subscription limit answers ResourceExhausted. A node that shuts down ends its
subscriptions with Unavailable; subscribe again at another node from your
last position. An expired token also ends the subscription.
Trim records
POST /v1/streams/{bucket}/{key}/trimgRPC: DataPlaneService.Trim. Moves the stream's trim watermark forward:
every record before the point becomes unreadable at once, and Nova reclaims its
storage later, in the background. Returns 204 with no body.
| Body field | Type | Meaning |
|---|---|---|
seq_num | integer | Trim every record before this sequence number |
timestamp_ms | integer | Trim every record stamped before this time |
bookmark | string | Trim every record before this bookmark, on either kind of stream |
Send exactly one.
curl -s -X POST localhost:8080/v1/streams/demo/events/trim -d '{
"seq_num": 2
}'
curl -s 'localhost:8080/v1/streams/demo/events/records?seq_num=0'{
"error": "reader: read 01a203c4-1aa9-7afc-8182-d776f724929f from 0 below the watermark 2: reader: entries trimmed"
}The watermark only moves forward: a point below it changes nothing and still
returns 204. A point past the tail trims every record. The remaining records
keep their sequence numbers. Trimming needs the trim grant, which is separate
from delete. See Trimming, and
Trim a stream for the SDK call.
| Status | When | Retry |
|---|---|---|
| 400 | No point, two points, or a bad bookmark. With reason: position_per_range, a seq_num on a scalable stream | No. Trim a scalable stream by bookmark or time |
| 404 | The stream does not exist. Trimming never creates one | No |
409 with reason: queue_address | The address is a queue's. A queue's messages leave by acknowledgement and age; use its purge route | No |
| 503 | The leader is moving or the node is draining | Yes, after Retry-After |
Over gRPC, the point is seq_num or timestamp_ms, the response is empty, and
the leader serves the call.
Fence a stream
POST /v1/streams/{bucket}/{key}/fencegRPC: DataPlaneService.Fence. Installs, replaces, or clears the stream's
fencing token, and returns the position where the change took effect.
Fence is the only way to install a token: an append only presents one. See
Writer coordination, and
Take over with a fencing token
for the SDK call.
| Body field | Type | Default | Meaning |
|---|---|---|---|
fencing_token | string | Empty | The token to install, at most 36 bytes of UTF-8. Empty or absent clears the token |
The body must be a JSON document, so send {} to clear.
curl -s -X POST localhost:8080/v1/streams/demo/events/fence -d '{
"fencing_token": "writer-1"
}'{
"tail": {
"seq_num": 5,
"timestamp_ms": 1795359533400
}
}Every record before tail was appended under the old token. Before it answers,
the leader ends every session whose token no longer matches. An append that
presents another token now fails:
curl -s localhost:8080/v1/streams/demo/events/records -d '{
"records": [
{
"body": "stale"
}
],
"fencing_token": "writer-0"
}'{
"error": "writer: open 01a203c4-1aa9-7afc-8182-d776f724929f presenting \"writer-0\": writer: fencing token mismatch: installed \"writer-1\"",
"fencing_token": "writer-1",
"fence_caller": true
}On a stream whose producer policy is any, an append without a token still
succeeds. On a fenced stream, every append must present the installed token.
A scalable stream answers a bookmark in place of tail. Fencing needs the
append grant.
| Status | When | Retry |
|---|---|---|
| 400 | The body is not a JSON document | No |
| 404 | The stream does not exist. Fencing never creates one | No |
409 with reason: queue_address | The address is a queue's | No |
| 500 | The token is longer than 36 bytes | No. Shorten the token |
| 503 | The leader is moving, or the stream has no leader and Nova is still recovering what the last writer left | Yes, with the same token |
A refused fence on a plain stream changed nothing, so you can send it again. On
a scalable stream, Fence sets the token on the stream first and then on each
range. A 503 whose error says retry to complete means the token is already
set: send the same fence again to finish.
Read plans
gRPC only: DataPlaneService.ReadPlan names the objects in storage that hold
a stream's older records, so a reader can fetch them itself instead of through
a node. The Gateway uses it to serve history. Read plans
documents the call.