Records

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.

OperationHTTPgRPC
AppendPOST /v1/streams/{bucket}/{key}/recordsAppend, AppendSession
ReadGET /v1/streams/{bucket}/{key}/recordsRead
Check the tailGET /v1/streams/{bucket}/{key}/records/tailCheckTail
SubscribeGET /v1/streams/{bucket}/{key}/records/subscribeSubscribe
TrimPOST /v1/streams/{bucket}/{key}/trimTrim
FencePOST /v1/streams/{bucket}/{key}/fenceFence
Read planNoneReadPlan

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 parameterMeaning
bucketThe stream's bucket
keyThe 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.

A position
{
  "seq_num": 1,
  "timestamp_ms": 1795359513291
}
A record, as a read returns it
{
  "seq_num": 1,
  "timestamp_ms": 1795359513291,
  "body": "world",
  "headers": [
    {
      "name": "content-type",
      "value": "text/plain"
    }
  ]
}
FieldTypeMeaning
seq_numintegerThe record's sequence number. At an end or a tail, one past the last record
timestamp_msintegerUnix milliseconds. At an end or a tail, the last record's time, or 0 when none is known
body, body_b64stringThe body, as text or as base64. Bodies and bytes says which one you get
headersarray{name, value} pairs, in order. Absent when the record has none
rangestringOn 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}/records

gRPC: 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.

recordsarrayRequired
The batch: 1 to 1,000 records and at most 1 MiB of content by default
records[].bodystringRequired
The body as text. Nova stores its UTF-8 bytes. Send this or body_b64
records[].body_b64stringRequired
The body as base64, for any bytes. Send this or body
records[].headersarrayDefaultNone
Each {"name": …, "value": …} or their _b64 forms. At most 64 through the Gateway and over gRPC, 100 on a node's data bridge; see Records and positions
records[].timestamp_msintegerDefaultThe arrival time
The record's time, used as the stream's timestamping mode allows
match_seq_numintegerDefaultNone
Append only if the first record would get this sequence number
fencing_tokenstringDefaultNone
Append only if this equals the stream's fencing token
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
}'
412 Precondition Failed
{
  "error": "writer: append at 2, expected 3",
  "tail": {
    "seq_num": 3,
    "timestamp_ms": 1795359513525
  }
}
StatusWhenRetry
400The 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 refusesNo. Fix the request
400One record holds more than 1 MiB of body and headers. Nothing was appendedNo. Store a larger payload in object storage and append a pointer to it
400 with reason: batch_too_largeMore than 1,000 records, or more than 1 MiB of content in allNo. Split the batch
400On a node's data bridge, a record with more than 100 headersNo. Send at most 64 headers
404The bucket or stream does not exist, and the bucket does not create streams on appendAfter you create it
412 with tailmatch_seq_num is not the stream's next sequence number. Nothing was appendedWith tail.seq_num, once you know your records are not already there
412 with fencing_tokenfencing_token does not match the installed token, or the stream is fenced and you sent noneOnly with the token the body names, if you mean to take over
413The body is over about 6.3 MiB, or one record's JSON is over about 1.36 MiBNo. Send fewer records, or the body as body_b64
429The node or the Gateway is short of capacity. retry_after_ms says when to try againYes, after retry_after_ms
500Through the Gateway, a record with more than 64 headersNo. Send at most 64 headers
503The stream's leader is moving, the node is draining, or another writer holds a fenced stream, which takes one writer at a timeYes, 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}/records

gRPC: 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:

QueryTypeMeaning
fromstringbeginning for the first record still stored, tail for only what comes next, or a bookmark
seq_numintegerThe record with this sequence number
timestamp_msintegerThe first record stamped at or after this time
tail_offsetintegerThis many records before the tail

When it stops, at whichever comes first:

QueryTypeDefaultMeaning
limitinteger8,192The most records. A larger value is cut to the node's limit, 8,192 by default
max_bytesinteger8 MiBThe most content bytes, cut to the node's limit, 8 MiB by default. One record always returns, however large
until_msintegerNoneStop before the first record stamped at or after this time

How the answer looks:

QueryTypeDefaultMeaning
clampbooleanfalseStart a read below the trim watermark at the first stored record. Without it, such a read fails with 410
formatstringrawraw 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.

StatusWhenRetry
400No start, two starts, a bad number, or an unknown format. With reason: position_per_range, a seq_num or tail_offset on a scalable streamNo. On a scalable stream, start from a bookmark, beginning, tail, or a time
404The stream does not exist, and the bucket does not create streams on readAfter you create it
410The start is below the trim watermarkWith from=beginning or clamp=true
503The node cannot serve the stream right nowYes, 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/tail

gRPC: 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.

StatusWhenRetry
404The stream does not exist. Checking the tail never creates oneAfter you create it
503The leader is moving or the node is drainingYes, after Retry-After

Over gRPC, a node that does not lead the stream answers FailedPrecondition with NotOwner.

Subscribe

GET /v1/streams/{bucket}/{key}/records/subscribe

gRPC: 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.

ParameterInMeaning
Last-Event-IDHeaderResume after the last event you received. It wins over the query
from, seq_num, timestamp_ms, tail_offsetQueryWhere to start, as on read. One is required without Last-Event-ID
formatQueryraw 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}}

: hb

Each 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/subscribe
id: 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.

StatusWhenRetry
400No start, or a Last-Event-ID that is not a bookmarkNo
404The stream does not exist, and the bucket does not create streams on readAfter you create it
503The host is at its limit of long-lived connections, 4,096 by defaultYes, 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}/trim

gRPC: 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 fieldTypeMeaning
seq_numintegerTrim every record before this sequence number
timestamp_msintegerTrim every record stamped before this time
bookmarkstringTrim 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'
410 Gone
{
  "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.

StatusWhenRetry
400No point, two points, or a bad bookmark. With reason: position_per_range, a seq_num on a scalable streamNo. Trim a scalable stream by bookmark or time
404The stream does not exist. Trimming never creates oneNo
409 with reason: queue_addressThe address is a queue's. A queue's messages leave by acknowledgement and age; use its purge routeNo
503The leader is moving or the node is drainingYes, 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}/fence

gRPC: 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 fieldTypeDefaultMeaning
fencing_tokenstringEmptyThe 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"
}'
412 Precondition Failed
{
  "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.

StatusWhenRetry
400The body is not a JSON documentNo
404The stream does not exist. Fencing never creates oneNo
409 with reason: queue_addressThe address is a queue'sNo
500The token is longer than 36 bytesNo. Shorten the token
503The leader is moving, or the stream has no leader and Nova is still recovering what the last writer leftYes, 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.

On this page