Persistence allows LangGraph applications to save state and resume from any point, enabling durable execution and human-in-the-loop workflows.
Checkpointers
Checkpointers save graph state at each step, creating a complete execution history.
InMemorySaver
For development and testing:
InMemorySaver is only for debugging and testing. Use a persistent checkpointer for production.
PostgresSaver
For production use with PostgreSQL:
SQLite Saver
For local persistence:
Thread Management
State Inspection
Get Current State
Access State History
Filter History
Time Travel
Rewind and replay from any checkpoint:
State Updates
Modify state before resuming:
Checkpoint Configuration
Setup Database Schema
Connection Pooling
For production, use connection pooling:
Durability Modes
Control when checkpoints are saved:
- sync: Safest, slowest - checkpoint saved before next step
- async: Faster - checkpoint saved in background
- exit: Fastest - only checkpoint at end
Serialization
Customize how state is serialized:
Best Practices
- Use thread IDs consistently: Map thread IDs to user sessions or conversation IDs
- Handle checkpoint errors: Wrap checkpoint operations in try/except blocks
- Clean old checkpoints: Implement cleanup for old or completed threads
- Test with real checkpointers: Don’t rely on InMemorySaver for production testing
- Monitor checkpoint size: Large states may need optimization
- Use connection pooling: For production PostgreSQL deployments
- Index your queries: Add database indexes on thread_id for performance
Cleanup
Remove old checkpoints:
Next Steps
- Implement Memory for long-term storage across threads
- Add Interrupts for human-in-the-loop workflows
- Learn about Deployment for production systems