The Information System: State, Context, and Views
In Happen, information flows naturally through the system in multiple complementary forms. The Information System builds on our core primitives—Nodes and Events—while providing powerful capabilities for managing, accessing, and transforming information across your application. This document explains the conceptual model and practical implementation of state, context, and views in Happen.
The Information System is built on three fundamental concepts:
State: What You Own
State is information that a node has authority over. It's the internal data that the node manages, updates, and is responsible for. State represents "what you know and control" within your domain.
State in Happen is:
Authoritative - The owning node is the single source of truth
Persisted - State can be saved and restored
Encapsulated - Direct modification is restricted to the owning node
Verifiable - State changes are tracked in the causal chain
// Basic state access
const orderNode = createNode("order-service");
// Read state directly
const state = orderNode.state.get();
const pendingOrders = Object.values(state.orders || {})
.filter(order => order.status === "pending");
// Transform state using a function approach
orderNode.state.set(state => {
return {
...state,
orders: {
...state.orders,
"order-123": {
customerId: "cust-456",
items: [{productId: "prod-789", quantity: 2}],
status: "pending"
}
}
};
});State can also be accessed selectively, using transformations to extract only the required data:
Global State Implementation
Happen's provides system-wide, crossboundary global state for universal data access throughout the unified event space. Global state is implemented using NATS Key-Value store and is accessible from all environments:
Unified Access: All nodes use the same
node.globalAPI regardless of environmentNative Transport Adapters: NATS provides native support for various transports:
TCP for server-to-server communication
WebSocket for browser and edge clients
TLS/WSS for secure communication
Consistent Experience: The same operations work identically across all environments
This approach leverages NATS' built-in transport capabilities to provide a seamless global state experience without requiring custom protocol adaptations.
For example, storing and retrieving data works the same way everywhere:
Context: What Happened and Why
Context is information that flows with events, providing essential metadata about causality, origin, and relationships. Context represents the "why" and "how" of information flow in the system.
Context in Happen is:
Causal - Tracks relationships between events
Automatic - Flows naturally with events
Enriched - Gains additional information as it flows
Structured - Organized into specific categories
Context is system-managed and automatically flows with events, requiring no manual manipulation.
Views: Windows Into Other Nodes
Views in Happen provide a window into other nodes' state, enabling coordinated operations across node boundaries. While conceptually simple, views are implemented using an elegant recursive traversal approach that leverages JavaScript's reference passing.
The Recursive Reference Collection Mechanism
At the core of Happen's view implementation is a recursive traversal of the node graph, combined with a shared reference mechanism.
When a node accesses a view, the system:
Creates a shared reference container (typically an object or array)
Passes this container to the target node
The target node deposits its state into the container
The original node can then access this state through the container
This mechanism provides several key advantages:
Performance: No need to copy large state objects
Freshness: Always gets the latest state when accessed
Simplicity: Minimal API surface for powerful functionality
Consistency: Predictable access patterns across different node types
Basic View Usage
Enhanced View Collection
For more efficient collection of state from multiple nodes in a single operation, Happen provides an enhanced collection capability:
This approach:
Traverses the node graph only once
Collects specific slices of state from each relevant node
Transforms the state during collection
Returns a unified object with all the collected data
For more advanced view patterns and usage, see the dedicated State Management page.
The Unified Information System
These three concepts—State, Context, and Views—form a unified information model:
State represents what a node owns and controls
Context represents the causal flow of information through events
Views represent windows into state owned by others
Each serves a distinct purpose in the system, creating a complete information model without redundancy or overlap.
How These Systems Work Together
The power of Happen's information system comes from how these complementary systems work together:
Context + Views
Context and views work together to provide a complete picture of system behavior:
State + Context = Causal State History
The combination of state and context enables rich causal state history:
State + Views = System-Wide View
The combination of state and views provides a system-wide view:
Practical Example: Coordinated Operations
Here's a complete example showing how views enable coordinated operations across node boundaries:
The Information System provides a complete model for managing, accessing, and transforming information through three complementary concepts:
State: What nodes own and control
Context: The causal flow of information through events
Views: Windows into state owned by others
Each plays a distinct role, working together to create a powerful yet conceptually clean information model:
State provides ownership and authority
Context provides causality and correlation
Views provide access and visibility
With enhanced view collection capabilities, the Information System enables complex, coordinated operations across node boundaries while maintaining clean separation of concerns and adhering to Happen's philosophy of radical simplicity.
Last updated