State management is the architectural discipline of capturing, evolving, and persisting the "current truth" of a system. As systems transition from simple CRUD to complex, long-running processes—particularly in AI-driven or distributed environments—state management moves from a localized implementation detail to a core architectural concern.
In the frontend, state management focuses on synchronizing the UI with underlying data while maintaining performance through unidirectional data flow.
is_open, input_value).theme, locale). It is not a high-frequency state management tool due to re-render overhead.When building Agentic Workflows, state is not just data—it is a progression of intent. AI agents require structured state machines to prevent infinite loops and ensure task completion.
A common agentic pattern uses a Finite State Machine (FSM) to govern the agent's behavior:
| State | Action | Next State (Success) | Next State (Fail) |
|---|---|---|---|
| Planning | LLM generates a task list | Executing | Planning (Re-plan) |
| Executing | Tool use / Code execution | Reflecting | Executing (Retry) |
| Reflecting | LLM evaluates the result | Planning (Next Task) | Executing (Correction) |
| Finished | Final answer returned | - | - |
Agent state typically consists of:
In backend systems, state is often moved via Event-Driven Transitions. Instead of imperatively setting status = 'SHIPPED', the system emits a SHIPPING_LABELED event, and the state machine transitions the aggregate.
CANCELLED to SHIPPED).Example State Machine Configuration (JSON-based):
{
"id": "order_fulfillment",
"initial": "unpaid",
"states": {
"unpaid": {
"on": { "PAYMENT_RECEIVED": "paid" }
},
"paid": {
"on": {
"INVENTORY_RESERVED": "ready_to_ship",
"CANCELLED": "refund_pending"
}
},
"ready_to_ship": {
"on": { "SHIPPING_LABEL_GENERATED": "shipped" }
}
}
}
For processes that last hours, days, or months, state must survive process restarts and server failures. Durable Execution patterns (pioneered by Temporal) ensure that the state of a function—including its local variables and stack—is persisted.
| Need | Pattern | Recommended Tooling |
|---|---|---|
| Simple UI Sync | Reactive Hook | useState / Zustand |
| Long-running Transaction | Saga Pattern | SagaPattern |
| Complex AI Reasoning | FSM / Task Graph | LangGraph / XState |
| Distributed Reliability | Durable Workflow | Temporal / Azure Durable Functions |
| Perfect Audit Trail | Event Sourcing | EventSourcing |