Appearance
State & Runtime
Every node has a central state object that holds all runtime data. Think of it as the brain of the node — it knows about every connection, every subscription, every cache entry, and every peer.
The State Instance
Access the state through the app:
cpp
auto state = app.get_state();The state is thread-safe. All operations on connections, subscriptions, and registries go through the state.
What the State Holds
state::instance
├── id — This node's UUID
├── configuration — The loaded config
├── clients — Client registry
│ ├── HTTP connections
│ ├── WebSocket connections
│ ├── TCP connections
│ ├── Router (routes)
│ └── Subscriptions & Channels
├── nodes — Inter-node connections & peer registry
│ └── gossip::engine — SWIM-style gossip protocol
│ └── raft::engine — Raft consensus engine
├── cache — Distributed key-value store
├── jobs — Queue manager & job factories
├── database — Connection pools
├── watchers — Real-time monitoring subscriptions
├── tasks — Scheduled tasks
├── wal — Write-ahead log
├── quota_evaluator — Rate limiter state
├── ssl_context — TLS context for encrypted connections
└── clock — Vector clock for cache consistency (tracks causal order of writes across nodes)Accessing Registries
cpp
// All connected clients
auto& clients = state->of_clients();
// All peer nodes
auto& nodes = state->of_nodes();
// Distributed cache
auto& cache = state->of_cache();
// Job queues
auto& queues = state->of_jobs();
// Database connection pools
auto& db = state->of_database();
// Real-time watchers
auto& watchers = state->of_watchers();
// Gossip engine (failure detection)
auto& gossip = state->of_gossip();
// Raft engine (consensus)
auto& raft = state->of_raft();
// Write-ahead log
auto& wal = state->of_wal();
// Quota evaluator (rate limiting)
auto& quotas = state->of_quotas();Why This Matters
Because all state is centralized, different parts of your service can interact seamlessly:
- An HTTP handler can publish to a Pub/Sub channel
- A WebSocket handler can read from the cache
- A mesh node can dispatch a job to a queue
Everything is connected through the state.
Next up: HTTP Routing.