folkwaysDocs
Realtime APIPayload format

Schemas: validation and evolution

Validate event payloads where you receive them, and change payload schemas without breaking older apps.

A topic rule decides which event names, types and operations are allowed. It doesn't check payloads. A TypeScript event map catches mistakes in your own code, but an outdated or malicious client can still send any shape. Validate payloads where you receive them.

Validate on the way in

TypeScript
import { z } from 'zod';

const ChatMessage = z.object({ text: z.string().min(1).max(2000) });

room.subscribe((message) => {
  if (message.name !== 'message') return;
  const parsed = ChatMessage.safeParse(message.data);
  if (!parsed.success) return; // ignore what doesn't fit
  render(message.publisher, parsed.data.text);
});

The same in JSON Schema, for other languages:

JSON
{
  "type": "object",
  "required": ["text"],
  "properties": { "text": { "type": "string", "minLength": 1, "maxLength": 2000 } },
  "additionalProperties": false
}
  • Use the event's publisher, verified by Folkways, as the sender. Never an identity inside the payload.
  • For binary formats, verify the buffer first, then check the values: a well-formed number can still be wrong for your business.
  • For actions that matter, such as payments or permission changes, route the request through your backend, which validates it and keeps the record, then publishes the result.

There is no schema registry in Folkways: keep schemas, fixtures and compatibility tests with your code.

Change schemas safely

Your payload schemas, the Realtime API version and the SDK version change independently.

  • Additive changes are safe: new optional fields with sensible defaults. Make readers ignore fields they don't know.
  • Never repurpose a field. In Protobuf, reserve removed numbers; in FlatBuffers, append fields and keep existing ones.
  • Breaking changes get a new event name or a new schema version. Move readers first, then writers.

Say which schema an event uses in a header:

TypeScript
await sensors.publish('reading', bytes, {
  contentType: 'flatbuffers',
  headers: { schema: 'fleet-reading', 'schema-version': '2' },
});

Test old readers against new writers and new readers against old writers, with real fixtures kept in your repository. If you publish both versions during a migration, remember each counts as a message, and make sure consumers don't act twice.

On this page