Producer sessions

Producer sessions

The append session over gRPC and HTTP, with its messages, flow control, failures, and the HTTP frame format.

A producer session sends many batches through one open request and gets an acknowledgement for each, in order, without waiting for one before sending the next. It is how the SDKs append at high throughput. This page is for writing a producer in a language without an SDK; with an SDK, the producer runs the session for you.

TransportHow to open
gRPCThe bidirectional stream DataPlaneService.AppendSession
HTTPPOST /v1/streams/{bucket}/{key}/records with Content-Type: application/vnd.nova.session, in frames

Messages

Both transports carry the same protobuf messages, AppendSessionRequest from the producer and AppendSessionResponse from the node:

MessageDirectionFields
AppendOpenTo the node, first onlybucket, key, fencing_token, and follows_batch_bound, which must be true
AppendOpenedFrom the node, first onlytail; max_inflight_bytes, the session window: 48 MiB on Standard and 8 MiB on Express; max_inflight_batches (1,024); max_batch_bytes and max_batch_records, the node's batch bound; max_batch_weight
AppendBatchTo the noderecords, and an optional match_seq_num
AppendAckFrom the node, one per batch, in orderstart, end, tail
AppendRejectedFrom the node, in the batch's placetail, when match_seq_num missed
open{stream, fencing_token} opened{tail, max_inflight_bytes} batch #1 batch #2 (match_seq_num) ack #1 {start, end, tail} rejected #2 {tail} batch #3 ack #3 Producer novad

Flow control

  • Send batches while their unacknowledged content fits max_inflight_bytes and their count fits max_inflight_batches. At either limit the node stops reading, and flow control makes your next send wait. Nothing is rejected.
  • Cut each batch within max_batch_bytes and max_batch_records. max_batch_weight also bounds a batch: its content plus 192 bytes a record, 128 a header, and 4 KiB a batch.
  • A match_seq_num miss rejects only that batch. The session goes on.
  • To finish, close your side. The node sends the remaining acknowledgements and then ends the session cleanly.

Failures

  • An open without follows_batch_bound fails with InvalidArgument: "this Nova SDK predates the 1 MiB / 1,000-record batch limit; upgrade the SDK". So does a first message that is not an open.
  • A batch over the bound ends the session with InvalidArgument, and nothing of that batch is appended. Any other failure also ends the session, and so does an expired token. Open a new session and resend the unacknowledged batches in order. A plain batch can be stored twice this way; a batch with match_seq_num cannot.
  • A node at its session limit answers ResourceExhausted. A node that does not lead the stream answers FailedPrecondition with NotOwner: open the session at the address it names.

HTTP frames

Over HTTP, a refusal at the open is an ordinary JSON error: 400, 403, 404, 412, 429, or 503. Once the session opens, the answer is 200 with the session content type, and both bodies are streams of frames.

Each frame is a 3-byte big-endian length, one flag byte, and a body. The length counts the flag byte and the body. A body is one of the protobuf messages above.

Flag bitsMeaning
1xxxxxxxTerminal: the body is a 2-byte big-endian HTTP status, then the JSON error document. The session is over
x00xxxxxUncompressed. The other compression values, and the five low bits, are reserved: a frame that sets one ends the session with terminal 400
  • A client frame's body holds at most one batch plus 1 MiB, 2 MiB by default. A longer frame ends the session with terminal 400 before the node reads it. A client never sends a terminal frame.
  • The node sends an empty frame every 15 seconds as a heartbeat. Ignore it.
  • Exactly one terminal frame ends a session. 200 with no document is a clean end, after you close the request body and the node has sent every acknowledgement. 503 means the node is draining, 401 that the token expired, and 400 a bad frame or a batch over the limit. Open a new session after you fix the cause.
  • A response that ends without a terminal frame means the connection broke.
  • A client that stops reading for 60 seconds is disconnected.

A session needs both directions of one request open at once: HTTP/2, or HTTP/1.1 where client and server both allow it. Proxies must forward request bodies as they arrive. A browser cannot open a session, because fetch waits for the request body to finish before it returns the response.

On this page