Primitives
Primitives
Stream, KV, Signal and Presence, the four ways Folkways keeps and delivers live data, and how to choose between them.
Every event on a topic is one of three types, and Folkways adds a fourth primitive, presence, on top of them. They are features of the service, not of an SDK: every client, in any language, gets the same behaviour.
| Stream | KV | Signal | Presence | |
|---|---|---|---|---|
| Keeps | Every event, in order | Latest value per key | Latest value per sender | One entry per connection |
| For how long | Up to 5 MiB, at most 24 h | Until replaced, deleted or expired | 5 s by default | While connected |
| New subscriber gets | Replay from a position, then live | Snapshot, then changes | Live signals, then new ones | Snapshot, then changes |
| Ordered | Yes, per topic | Latest wins | Latest wins | Latest wins |
| Retried safely | Yes, idempotency key | Latest wins | No: best effort | Written by Folkways |
| Op to write | publish | set | signal | none: automatic |
| Typical use | Messages, orders, AI tokens | Read receipts, scores, locations | Typing, cursors | Online lists, who's in a room |
Choosing
- Would a user be upset to miss it? Use a stream: messages, orders, notifications.
- Do you only care about the current value? Use KV: where each driver is, who read up to where, the score.
- Is it stale within seconds? Use a signal: typing, cursor position, "is speaking".
- Do you want to know who's around? Turn on presence for the topic's rule; nobody publishes anything.
A chat room uses all four on one topic: message as a stream, read as KV, typing as a signal, and presence to
list who's in the room. See the chat room example.