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.
| Part | What it is |
|---|---|
| Name | What happened: message, read, typing. 1–64 bytes of UTF-8 |
| Type | How Folkways keeps it: stream, kv or signal |
| Payload | Your data, as bytes. JSON is the usual choice; Folkways never reads it |
| Publisher | The sender's identity, set by Folkways from the verified token |
| Key | KV and signals only: which value it sets, e.g. a user or an item |
| Headers | Up to 16 string pairs your app defines, such as a schema version |
| Position | Stream only: a cursor (epoch, seq) and a permanent uid |
Event types
| Type | Folkways keeps | A new subscriber gets | Use it for |
|---|---|---|---|
| Stream | Every event, in order, within retention | A replay from a position it picks, then live events | Messages, orders, AI output |
| KV | The latest value per event name and key | A snapshot of current values, then changes | Read receipts, scores, locations, status |
| Signal | The latest value per event name and sender, for seconds | A snapshot of live signals, then new ones | Typing, cursors, "here now" |
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:
{
"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:
- If the rule's event map names the event, that type. Asking for another is refused with
ClassMismatch. - 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. - Otherwise the type the publisher asked for.
- 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:
| Type | Ops that allow writing it |
|---|---|
| Stream | publish |
| KV | set or publish |
| Signal | signal 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.