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 invoked with iii.trigger({ function_id: 'state::...', payload }). The worker also exposes state::list_keys and the internal state::ui-content function. Install it with iii trigger 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. Reactivity is delivered by a state trigger type that fires state:created, state:updated, or state:deleted after every successful mutation, so downstream functions can 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 trigger side effects elsewhere (cache invalidation, audit logs, notifications, projections).
- You want a specific
scope/keywatched and reacted to only when that slot changes.