Examples
State Management

State Management Example

This example demonstrates how to manage state within flows and steps in ZoopFlow. Proper state management is essential for building robust workflows that can track progress, store intermediate results, and maintain consistency.

What You'll Learn

  • How to use the state management APIs in flows and steps
  • How to store and retrieve state during workflow execution
  • How to share state between different steps
  • How to implement checkpoints in long-running workflows
  • How to handle state in error scenarios
  • Best practices for state management

Files in this Example

  • basic-state-management.ts - Demonstrates the fundamental state management APIs
  • shared-state-flow.ts - Shows how to share state between steps
  • checkpoint-example.ts - Implements checkpoints in long-running workflows
  • state-persistence.ts - Demonstrates state persistence across workflow executions
  • run-example.ts - Entry point to run the example

State Management Concepts

In ZoopFlow, state management:

  • Provides a key-value store for workflow data
  • Automatically persists state during workflow execution
  • Allows steps to communicate through shared state
  • Supports checkpointing for long-running processes
  • Ensures state consistency even in failure scenarios

How to Run

# From the project root
npm install
npx ts-node docs/new-structure/examples/state-management/run-example.ts

Expected Output

The example will:

  1. Demonstrate basic state operations (get, set)
  2. Show how state is shared between steps
  3. Implement checkpoint-based processing for large data sets
  4. Illustrate state persistence across workflow interruptions

Output will show the state changes throughout flow execution.

Next Steps

  • Implement your own state management patterns
  • Explore advanced state management with transactions
  • Learn about state management with Temporal in the Temporal Integration Example
  • Implement state management in a real-world use case