State & Data¶
Beyond messages, rEEEductio provides two lighter-weight storage primitives: State and Data. Both live inside a space, both are encrypted, and both are designed for structured metadata rather than conversation streams.
State — event-sourced paths¶
State is a key-value store where each path has a history. Every write creates a new entry in an append-only event log, so you can always look back at what a value was at any point in time.
Think of it like a Git repository for your configuration: you see the current value at HEAD, but the full history is always there.
What state is good for¶
- User profiles and preferences
- Access control lists (who has what role)
- Application configuration
- Audit logs of setting changes
State paths¶
Paths use a slash-separated hierarchy (e.g. profiles/alice, config/feature-flags). The current value at a path is the most recent write to that path.
Note
State paths are different from topic IDs. They can contain slashes and are not subject to the same character restrictions as topic names.
Reading and writing state¶
import { stringToBytes, bytesToString } from 'reeeductio';
// Store a user profile (plaintext)
await space.setPlaintextState('profiles/alice', stringToBytes('{"name": "Alice", "role": "admin"}'));
// Read it back
const profileBytes = await space.getPlaintextState('profiles/alice');
console.log(bytesToString(profileBytes));
Encrypted state¶
For sensitive values (tokens, private settings), use the encrypted variants. The SDK uses stateKey (derived from symmetricRoot) to encrypt client-side before sending:
State history¶
Since state is event-sourced, you can retrieve the full change history:
Data — lightweight key-value pairs¶
Data is a simpler, flat key-value store. Each entry is a single value at a path, with no history. It's optimized for values that change frequently and where you only ever care about the latest value.
Each data entry is signed by the writer, so you can verify authenticity, but it is not chained — there's no prev_hash.
What data is good for¶
- Presence and availability status
- Ephemeral metadata (e.g. "user is typing")
- Counters and cursors
- Short-lived configuration flags
Reading and writing data¶
State vs. Data — which to use?¶
| State | Data | |
|---|---|---|
| History | Full history preserved | Latest value only |
| Integrity | Hash-chained, tamper-evident | Signed, no chain |
| Encryption | Optional (plaintext or encrypted) | Signed; encryption optional |
| Best for | Config, profiles, audit logs | Presence, ephemeral metadata |
When in doubt: if you might ever want to know what the value was at some point in the past, use State. If you only care about the current value, use Data.
Related concepts¶
- Spaces — State and Data both live inside a space
- Topics & Messages — for ordered event streams and chat
- Blobs — for large binary payloads