AI / CrewAI Interview Questions II
Explain the lifecycle of state persistence in a Flow using the @persist decorator?
- Initialization: a Flow instance is created and automatically assigned a unique identifier, a UUID, as part of its state
- Execution: as @start, @listen, and @router methods run, they read from and write to the Flow's state, whether unstructured as a dictionary or structured as a Pydantic model
- Persistence: with @persist applied to the Flow class, this state is written out to a backing store, SQLite by default, or PostgreSQL for multi-instance deployments, as execution proceeds
- Interruption: if the Flow is interrupted, whether by a crash, a deliberate pause such as @human_feedback, or a restart, its state isn't lost
- Recovery: on resumption, the Flow reloads its persisted state and continues rather than starting over from the beginning
This lifecycle is specifically what makes long-running or human-in-the-loop Flows viable in production, without it, any interruption would force the entire workflow to restart from scratch, discarding whatever progress had already been made.
More Related questions...