folkwaysDocs
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 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.
StreamKVSignalPresence
KeepsEvery event, in orderLatest value per keyLatest value per senderOne entry per connection
For how longUp to 5 MiB, at most 24 hUntil replaced, deleted or expired5 s by defaultWhile connected
New subscriber getsReplay from a position, then liveSnapshot, then changesLive signals, then new onesSnapshot, then changes
OrderedYes, per topicLatest winsLatest winsLatest wins
Retried safelyYes, idempotency keyLatest winsNo: best effortWritten by Folkways
Op to writepublishsetsignalnone: automatic
Typical useMessages, orders, AI tokensRead receipts, scores, locationsTyping, cursorsOnline 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.

Using them

On this page