Skip to main content
State in iii is a distributed key-value store addressed by scope (group) + key (item ID). Any worker can read and write state by triggering state::get, state::set, state::delete, and state::list through the engine.

Writing state

Reading state

Batch read with state::list

state::list returns all keys in a scope — useful in cron jobs that sweep over accumulated data.

State API reference

Key concepts

  • State is addressed by scope (equivalent to groupId in streams) and key (item ID). Use scope as a logical namespace ("users", "orders") and key as the unique identifier within it.
  • state::list returns all items in a scope as an array. Use it sparingly in hot paths; it’s best suited for cron-driven batch sweeps.
  • State is separate from named streams. Streams have real-time WebSocket push; state does not.
  • For partial mutations, prefer state::update with atomic ops (set, merge, append, increment, decrement, remove) over read-modify-write with state::set. The merge op accepts either a single string (first-level field) or an array of literal segments for nested merge. See iii-state worker reference for the ops table and Build per-session structured state with nested merge for a full example.