folkwaysDocs
Concepts

Events

What an event is, its name, type, key and payload, and how a topic decides each event's type.

An event is one thing published to a topic: a chat message, a read receipt, a keystroke, a location fix.

PartWhat it is
NameWhat happened: message, read, typing. 1–64 bytes of UTF-8
TypeHow Folkways keeps it: stream, kv or signal
PayloadYour data, as bytes. JSON is the usual choice; Folkways never reads it
PublisherThe sender's identity, set by Folkways from the verified token
KeyKV and signals only: which value it sets, e.g. a user or an item
HeadersUp to 16 string pairs your app defines, such as a schema version
PositionStream only: a cursor (epoch, seq) and a permanent uid

Event types

TypeFolkways keepsA new subscriber getsUse it for
StreamEvery event, in order, within retentionA replay from a position it picks, then live eventsMessages, orders, AI output
KVThe latest value per event name and keyA snapshot of current values, then changesRead receipts, scores, locations, status
SignalThe latest value per event name and sender, for secondsA snapshot of live signals, then new onesTyping, cursors, "here now"
Stream keeps every event in order and gives a new subscriber a replay from a chosen position, then every new event. KV keeps the latest value per key, so after read alice=#2, read bob=#3 and read alice=#4 a new subscriber gets a snapshot alice=#4, bob=#3, then each change. Signal keeps the latest per sender and expires it; a new subscriber gets the signals still alive, then new ones, best effort.

One topic, several types

A topic rule lists the types its topics may carry, and can fix each event name to one type with an event map:

Topic rule
JSON
{
  "pattern": "rooms/*",
  "types": ["stream", "kv", "signal"],
  "events": {
    "message": "stream",
    "read": { "delivery": "kv", "key_is_publisher": true },
    "typing": "signal"
  }
}

The type of an event is decided in this order:

  1. If the rule's event map names the event, that type. Asking for another is refused with ClassMismatch.
  2. If the rule has an event map and doesn't name the event, the publish is refused with ClassMismatch, unless the rule turns strict event names off.
  3. Otherwise the type the publisher asked for.
  4. Otherwise the rule's only type, or stream when it allows several.

Fixing names to types in the rule is the safest choice: a client can't send a keystroke as a stream event, or a message as a signal.

Rights per type

Writing needs the right op in both the token and the rule:

TypeOps that allow writing it
Streampublish
KVset or publish
Signalsignal or publish

Keys

KV values and signals are stored under a key. For KV it defaults to the publisher's identity, so read with no key means "this user's read receipt". Set your own key for shared values, such as a score per match.

With key_is_publisher on a KV event, nobody but your backend can write or delete someone else's key, so a user can't move another user's read receipt.

Payloads

The payload is opaque bytes, at most 60 KiB (61,440 bytes), or less if the segment or rule sets a lower limit. A content type label (JSON, text, bytes, FlatBuffers, Protobuf, MessagePack, CBOR, or your own) tells receivers how to decode it; Folkways doesn't check it. See Payload format.

IDs: uid, cursor and display id

  • Stream and KV events get a uid, a UUIDv7 that never changes. Point read receipts, edits and reactions at the uid.
  • Stream events also have a cursor (epoch, seq): their position, for resuming. A cursor can change meaning when the epoch changes, so never use it as a permanent reference.
  • Signals get neither: they are meant to vanish.

See Delivery and ordering for cursors.

On this page