> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Stateful Persistence Checkpoints

> Describes LangGraph's checkpointing to persist workflow runtime state for pause and resume, crash recovery, backend options, security, and production best practices.

LangGraph enables agents to persist runtime state so workflows can pause and resume without losing progress. This capability is critical for real-world automation that spans hours or days, depends on external systems, or requires user input across multiple sessions.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/A72Yow2kiLd9Lv77/images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/stateful-persistence-robot-workflows-diagram.jpg?fit=max&auto=format&n=A72Yow2kiLd9Lv77&q=85&s=2888bf9ea5af4cb0d665333a93bcfd0e" alt="The image explains the importance of stateful persistence, showing a robot managing state during pause and resume states with benefits like long workflows, external dependencies, and multi-session input." width="1920" height="1080" data-path="images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/stateful-persistence-robot-workflows-diagram.jpg" />
</Frame>

## What is stateful persistence?

Stateful persistence (checkpointing) saves the full runtime state of a graph—data, counters, flags, loop positions, and execution context—so an agent can be paused and later resumed from the same point. Checkpoints are durable: they live outside process memory in a database or object store, similar to saving a game's progress.

Consider a tax-filing chatbot: if the user goes idle mid-session, checkpointing ensures the assistant resumes from the exact step rather than starting over.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/A72Yow2kiLd9Lv77/images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/stateful-persistence-graph-overview-diagram.jpg?fit=max&auto=format&n=A72Yow2kiLd9Lv77&q=85&s=76998eb4567d63127c2fdf07eda66310" alt="The image illustrates an overview of stateful persistence, showing the process of saving the state of a graph, including data, counters, flags, and loop status, into a stateful persistence vault, followed by a durable checkpoint and storage in a database and file storage." width="1920" height="1080" data-path="images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/stateful-persistence-graph-overview-diagram.jpg" />
</Frame>

## Real-world analogy

Imagine a delivery driver, Ravi. He pauses mid-route for lunch and marks which deliveries remain. When he resumes, he continues from that checkpoint—no need to redo completed deliveries. The same concept applies to workflow checkpoints.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/A72Yow2kiLd9Lv77/images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/stateful-persistence-delivery-route-diagram.jpg?fit=max&auto=format&n=A72Yow2kiLd9Lv77&q=85&s=4beb062dea1fce3444d765f652a78913" alt="The image is a diagram labeled &#x22;Stateful Persistence – Overview,&#x22; showing a delivery route from an office to multiple houses, with stops for deliveries and lunch. The diagram includes a character named Ravi and a summary of delivery statuses." width="1920" height="1080" data-path="images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/stateful-persistence-delivery-route-diagram.jpg" />
</Frame>

## Why checkpointing matters

Checkpointing enables:

* Crash recovery and process restarts without losing progress.
* Long-running workflows that span sessions or human interactions.
* Pausing while waiting for external triggers (webhooks, API calls) or user confirmations, then resuming exactly where the workflow paused.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/A72Yow2kiLd9Lv77/images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/checkpointing-benefits-robot-icon.jpg?fit=max&auto=format&n=A72Yow2kiLd9Lv77&q=85&s=2256b4b68f18a2c46133a3c9177068bf" alt="The image illustrates &#x22;Checkpointing – Benefits&#x22; with a robot icon leading to &#x22;User Confirmation&#x22; and &#x22;API Response.&#x22;" width="1920" height="1080" data-path="images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/checkpointing-benefits-robot-icon.jpg" />
</Frame>

## Quick example — enable checkpointing (in-memory)

Below is a minimal Python example showing how to enable checkpointing with an in-memory checkpointer, compile a graph with persistence, run it (which saves state keyed by a `thread_id`), and later resume with the same `thread_id`.

```python theme={null}
from langgraph.checkpoint.memory import InMemorySaver

# Create a checkpointer and compile the graph with persistence enabled
checkpointer = InMemorySaver()
app = graph.compile(checkpointer=checkpointer)

# Use a thread_id to associate a session with its persisted state
config = {"configurable": {"thread_id": "session-123"}}

# First run: state is automatically checkpointed after each step
result = app.invoke(inputs, config=config)
print("First run result:", result)

# Later: resume using the same thread id and new inputs
resumed_result = app.invoke(new_inputs, config=config)
print("Resumed graph result:", resumed_result)
```

<Callout icon="lightbulb" color="#1CB2FE">
  Pick a `thread_id` that uniquely represents the user session or workflow instance. Treat thread IDs like session tokens and protect them with the same care as authentication credentials.
</Callout>

## Production backends and trade-offs

In production, checkpoint storage should be durable and secure. LangGraph supports pluggable checkpointers and common backends:

| Backend              | Best for                                  | Notes / Example                                                           |
| -------------------- | ----------------------------------------- | ------------------------------------------------------------------------- |
| Redis                | Real-time session storage, low-latency    | Very fast; good for ephemeral sessions and quick resume.                  |
| Cloud object storage | Long-term durable storage                 | Use `S3` or equivalent for archived or infrequently accessed checkpoints. |
| Databases            | Auditing, analytics, enterprise workflows | Relational or document DBs can store metadata and support queries.        |
| Custom checkpointers | Integrate with existing infrastructure    | Implement serialization and storage to match your requirements.           |

Be mindful of checkpoint frequency—excessively frequent saves increase overhead. Save at meaningful boundaries: task completion, decision points, or when waiting for user input.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/A72Yow2kiLd9Lv77/images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/langgraph-persistence-bookmark-process-diagram.jpg?fit=max&auto=format&n=A72Yow2kiLd9Lv77&q=85&s=78c471bbe3c5bacbffc11ecccd8a79b6" alt="The image illustrates how LangGraph handles persistence, showing a process where a state is bookmarked for later resumption, even after walking away, closing a tab, or shutting down." width="1920" height="1080" data-path="images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/langgraph-persistence-bookmark-process-diagram.jpg" />
</Frame>

## Common production use cases

* Asynchronous tasks: checkpoint before sending a message or webhook; resume when a callback arrives.
* Human-in-the-loop flows: pause while awaiting user verification and continue once confirmed.
* Crash recovery: reload the most recent checkpoint after an infrastructure failure.

Table: Example use cases and where checkpointing helps

| Use Case                 | When to checkpoint              | Benefit                                        |
| ------------------------ | ------------------------------- | ---------------------------------------------- |
| Webhook-driven process   | Before sending external request | Resume on callback without redoing prior steps |
| Multi-step approval      | After each approval stage       | Continue approval chain across sessions        |
| Long-running computation | At checkpoints between stages   | Recover progress if the process is interrupted |

When a graph is compiled with a checkpointer, LangGraph automatically stores the workflow state after each step, associating it with the configured `thread_id`. To resume, run the graph again with the same `thread_id` and the runtime will restore the last saved state and continue execution.

```python theme={null}
from langgraph.checkpoint.memory import InMemorySaver

checkpointer = InMemorySaver()

# Compile graph with persistence enabled
app = graph.compile(checkpointer=checkpointer)

config = {"configurable": {"thread_id": "user_123"}}

# Run graph - state is automatically checkpointed
app.invoke(state, config=config)

# Later: resume without losing progress
result = app.invoke(new_inputs, config=config)
print("Resumed graph result:", result)
```

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/A72Yow2kiLd9Lv77/images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/saving-checkpoint-langgraph-process.jpg?fit=max&auto=format&n=A72Yow2kiLd9Lv77&q=85&s=7b2f66ec6ded567def797473534b4ff7" alt="The image illustrates a process titled &#x22;Saving a Checkpoint&#x22; for a system named LangGraph, involving serialization, storage, and versioning. It also suggests configuring the checkpointer and using a thread_id to resume." width="1920" height="1080" data-path="images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/saving-checkpoint-langgraph-process.jpg" />
</Frame>

## Security & reliability considerations

Production checkpointing systems commonly include:

* Encryption and hashing of persisted states.
* Audit logs and metadata (timestamps, session IDs).
* Versioning and schema evolution support to maintain compatibility.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/A72Yow2kiLd9Lv77/images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/checkpoint-saving-methods-high-availability.jpg?fit=max&auto=format&n=A72Yow2kiLd9Lv77&q=85&s=324214ae4f7ed9aa9cb3d7920c2c5602" alt="The image outlines methods for saving a checkpoint in high-availability systems, including encrypting/hashing the state, logging for audit trails, and tagging the state with metadata. It highlights that this method provides a foundation for long-term and persistent AI workflows." width="1920" height="1080" data-path="images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/checkpoint-saving-methods-high-availability.jpg" />
</Frame>

<Callout icon="warning" color="#FF6B6B">
  Persisted state can contain sensitive data (PII, API keys, tokens). Always encrypt persisted checkpoints, restrict access with IAM, and maintain audit trails to meet compliance and security requirements.
</Callout>

## Resuming execution

When resuming, LangGraph:

1. Loads the latest checkpoint associated with the `thread_id`.
2. Reconstructs the runtime graph, including the last executed node and execution context.
3. Continues execution from that saved point.

Because the checkpoint stores both state data and execution context, resuming is deterministic and reliable.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/A72Yow2kiLd9Lv77/images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/langgraph-resuming-execution-process-diagram.jpg?fit=max&auto=format&n=A72Yow2kiLd9Lv77&q=85&s=5c36fd2e1fe12618b703ab29a114be9e" alt="The image outlines a process for &#x22;Resuming Execution&#x22; in a system called LangGraph, detailing steps like loading checkpoints and reconstructing runtime graphs, and explaining why this process works." width="1920" height="1080" data-path="images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/langgraph-resuming-execution-process-diagram.jpg" />
</Frame>

Resume patterns:

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/A72Yow2kiLd9Lv77/images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/resume-execution-methods-workflows-triggers.jpg?fit=max&auto=format&n=A72Yow2kiLd9Lv77&q=85&s=1bc48caf5bb60e581ea9c620f6022c25" alt="The image outlines three methods of resuming execution: user-driven continuation, multi-turn workflows, and external triggers, each with a brief description." width="1920" height="1080" data-path="images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/resume-execution-methods-workflows-triggers.jpg" />
</Frame>

* User-driven continuation: pause to ask clarifying questions and resume after a response.
* Multi-turn workflows: staged approvals or document reviews across sessions.
* External triggers: webhooks, scheduled jobs, or callbacks resume the workflow.

## Best practices

* Save checkpoints at meaningful boundaries (decision points, task completions).
* Choose a persistence backend aligned with latency, durability, and cost needs.
* Encrypt persisted data and maintain access logs.
* Treat checkpoint storage as critical infrastructure—implement monitoring, backups, and recovery plans.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/A72Yow2kiLd9Lv77/images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/best-practices-timing-data-protection-infrastructure.jpg?fit=max&auto=format&n=A72Yow2kiLd9Lv77&q=85&s=5a5ee501b78c3f21ff72977f1f87d681" alt="The image showcases three best practices: strategic timing, data protection, and critical infrastructure, each represented by a colored icon and brief description." width="1920" height="1080" data-path="images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/best-practices-timing-data-protection-infrastructure.jpg" />
</Frame>

## Key takeaways

* Checkpointing makes LangGraph agents robust to crashes and restarts.
* Persistence allows workflows to span multiple sessions and actors.
* Checkpoints preserve both workflow state and execution context, enabling precise resumption.
* Design checkpointing with security, durability, and operational controls in mind.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/A72Yow2kiLd9Lv77/images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/langgraph-persistence-key-takeaways.jpg?fit=max&auto=format&n=A72Yow2kiLd9Lv77&q=85&s=e5beb3c026d69f4bd01216121719e9b6" alt="The image lists four key takeaways about persistence in LangGraph agents, highlighting their robustness, session-spanning ability, workflow enablement, and reliability foundation." width="1920" height="1080" data-path="images/LangGraph/Long-Term-Memory-and-Stateful-Persistence/Stateful-Persistence-Checkpoints/langgraph-persistence-key-takeaways.jpg" />
</Frame>

## References

* Redis: [https://redis.io/](https://redis.io/)
* AWS S3: [https://aws.amazon.com/s3/](https://aws.amazon.com/s3/)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/langgraph/module/e0cd494a-00a7-4c52-88e9-b3932b03ff9f/lesson/61700334-8d53-4e7a-b8a3-23360d19e653" />
</CardGroup>
