folkwaysDocs
Realtime APIPayload format

Payload format

How events travel, from your payload bytes to frames, packets and WebSocket messages, and the content types receivers decode by.

There are two layers, and they are independent:

  1. Your payload: the bytes of your event, in whatever format you choose. JSON is the usual choice. Folkways never parses it.
  2. The protocol: FlatBuffers frames that carry your payload with its topic, name, type and headers. Clients use it whether the payload is JSON or binary. The JavaScript SDK handles it for you.

You don't need FlatBuffers to send JSON. And labelling a payload as FlatBuffers doesn't make Folkways read it.

One WebSocket binary message, or one HTTP request body, is one packet: a FlatBuffers buffer with identifier RTEC from clients or RTES from servers, at most 64 KiB. A packet holds 1 to 64 frames, each with a corr request ID and a body such as Publish. A Publish frame has a topic, name, delivery type, idempotency key, key and ttl, up to 16 headers, a content type and the payload: your bytes, at most 60 KiB, never parsed. HTTP responses carry several server packets, each prefixed by its little-endian u32 length.

Messages, packets and frames

LayerWhat it isLimit
MessageOne WebSocket binary message, or one HTTP request bodyOne packet
PacketOne FlatBuffers buffer. Client packets have the file identifier RTEC, server packets RTES64 KiB
Frame{ corr, body }: one request or reply. corr is your request ID, echoed on replies1 to 64 per packet
EventInside Deliver and Snapshot frames: one published item, with its payloadPayload 60 KiB

HTTP responses carry a sequence of server packets, each prefixed by its length as a little-endian u32: [u32 length][packet][u32 length][packet]….

The frame reference lists every frame and field.

Content types

Each event carries a content type: a 16-bit label telling receivers how to decode the payload. It is a hint, not validation.

NameValueUse
Unspecified0No declared format
Bytes1Opaque bytes, such as encrypted envelopes
Json2Objects and values; the default for most apps
Text3UTF-8 text
FlatBuffers4Generated binary structures; see FlatBuffers
Protobuf5Schema-defined binary messages
MsgPack6Compact objects
Cbor7Compact objects, common in IoT
your own1024–65535Your own encoding; agree on meanings across your apps

Values 8 to 1023 are reserved for future standard formats.

Which to choose. JSON is simplest for web apps. FlatBuffers lets readers access fields without unpacking the whole object. Protobuf has mature schemas and bindings everywhere. MessagePack and CBOR are compact object encodings. Measure with your own data before switching for size or speed. Don't base64-encode binary payloads into JSON: it adds about a third to their size.

Headers

Up to 16 string pairs per event, passed to every subscriber unchanged. Use them for metadata such as a schema version or a trace ID, never for secrets: anyone who can read the topic can read them.

The schema

The protocol's FlatBuffers schema is protocol.fbs in the JavaScript SDK's repository. Generate bindings for your language with flatc 24.3.25 (--ts, --python, --go, --java, --kotlin, --swift and others).

The schema evolves without breaking old clients:

RuleEffect
Fields are only added at the end of a tableOld clients ignore fields they don't know
Tags and enum values are never reusedA retired number stays empty
Unknown frame types are refused, never guessedA safe failure instead of a misread
Zero is always the cautious defaultAn unset field behaves the way an old client expects
A breaking change would be a new version with new identifiersIt would run beside v1

In this section

On this page