state
state
The state worker is a server-side key/value store. Values are addressed by a scope (namespace) and a key, shared across every worker connected to the engine, and persisted through a pluggable adapter (kv or redis). Callers reach the core store through six state::* functions called with iii.call({ function_id: 'state::...', payload }). The worker also exposes state::list_keys and the internal state::ui-content function. Install it with iii call compose::add worker=state; it replaces the engine's legacy built-in state service, which must be removed from the engine config first.
State does not push updates to SDK clients. After every successful mutation the worker calls state::on-changed with a state:created, state:updated, or state:deleted event; functions that observe it react to data changes without polling. The kv adapter (default) supports file_based persistence (the default) or a volatile in_memory mode; redis proxies to a Redis backend. The function surface is identical across adapters.
When to Use
- Two or more functions need shared state without standing up a separate database.
- A counter or per-entity document needs atomic partial updates instead of read-modify-write.
- A write in one function should cause side effects elsewhere (cache invalidation, audit logs, notifications, projections).
- You want a specific
scope/keywatched and reacted to only when that slot changes.