From Full Stack to AI: Checkpointing Workflow in LangGraph with MongoDB
How to Implement Checkpointing in LangGraph with MongoDB for AI and Full Stack Workflows

I’m a full-stack developer who enjoys building practical, scalable applications with React.js, Node.js, and Next.js. My journey into open source started with Hacktoberfest 2023, and it opened the door to real collaboration, learning from global contributors, and supporting early developers as they grow.
Since then, I’ve contributed to and mentored in programs like GSSoC’24, SSOC’24, and C4GT’24. As a Google Gen AI Exchange Hackathon ’24 Finalist and a Google Women Techmakers Ambassador, I’ve had the chance to help communities explore AI and build meaningful solutions. I’m also part of the Top 1% mentors on Topmate, where I guide students on open source, career building, and technical growth.
My work has been featured at Times Square NYC, and I’ve spoken on international podcasts about tech, learning, and community. I’ve also written technical content for CoderArmy and continue to share insights through articles and public posts. LinkedIn has recognized my work with seven Top Voice badges as well as Golden Badges in research, critical thinking, teamwork, and interpersonal skills.
I completed my MCA from Chandigarh University in 2023 and continue to stay curious by exploring AI, building new projects, and contributing to developer communities. Whether it’s improving a UI, debugging backend logic, or helping someone with their first pull request, I enjoy learning alongside others.
If you want to collaborate, learn together, or discuss an idea, feel free to reach out at kumaripayal7488@gmail.com
When I moved from full stack development to AI systems, one thing felt very familiar. State management.
In backend apps, we store user sessions in a database. In AI workflows, we also need memory. If an agent stops or crashes, we should not lose its progress.
That is where checkpointing in LangGraph becomes important.
What is Checkpointing
Checkpointing means saving the current state of your workflow at a specific point in time.
Think of it like saving a game. If your system stops, you can resume from the last saved point instead of starting again.
In LangGraph, a checkpoint stores:
config
metadata
values
next
tasks
In simple words, it stores everything needed to continue the workflow later.
Let us first see a basic LangGraph without checkpointing.
Basic Graph Without Persistence
from dotenv import load_dotenv
from typing_extensions import TypedDict
from typing import Annotated
from langgraph.graph.message import add_messages
from langgraph.graph import StateGraph, START, END
from langchain.chat_models import init_chat_model
load_dotenv()
llm = init_chat_model(
model="gpt-4.1-mini",
model_provider="openai",
)
class State(TypedDict):
messages: Annotated[list, add_messages]
def chatboat(state: State):
response = llm.invoke(state.get("messages"))
return {"messages": [response]}
def samplenode(state: State):
print("Inside samplenode node", state)
return {"messages": state["messages"] + ["Sample Message Appended"]}
graph_builder = StateGraph(State)
graph_builder.add_node("chatboat", chatboat)
graph_builder.add_node("samplenode", samplenode)
graph_builder.add_edge(START, "chatboat")
graph_builder.add_edge("chatboat", "samplenode")
graph_builder.add_edge("samplenode", END)
graph = graph_builder.compile()
updated_state = graph.invoke(State({"messages": ["What is my name?"]}))
print("updated_state", updated_state)
Example output:
Inside samplenode node {'messages': [...]}
updated_state {'messages': [...]}
Explanation:
The graph runs from START to chatboat to samplenode to END.
But once execution finishes, everything is gone. If you run it again, it does not remember anything.
Now let us add persistence.
Setting Up MongoDB with Docker
We need a database to store checkpoints. MongoDB is a simple choice.
Create a docker-compose.yml file:
services:
mongodb:
image: mongo
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: admin
volumes:
- mongodb_data:/data/db
volumes:
mongodb_data:
Run:
docker compose up -d
This starts MongoDB locally on port 27017.
Now we can use it as checkpoint storage.
Implementing MongoDB Checkpointer in LangGraph
LangGraph provides MongoDBSaver for storing checkpoints.
Here is a simple example.
from dotenv import load_dotenv
from typing_extensions import TypedDict
from typing import Annotated
from langgraph.graph.message import add_messages
from langgraph.graph import StateGraph, START, END
from langchain.chat_models import init_chat_model
from langgraph.checkpoint.mongodb import MongoDBSaver
import os
load_dotenv()
llm = init_chat_model(
model="gpt-4.1-mini",
model_provider="openai",
)
class State(TypedDict):
messages: Annotated[list, add_messages]
def chatboat(state: State):
response = llm.invoke(state.get("messages"))
return {"messages": [response]}
graph_builder = StateGraph(State)
graph_builder.add_node("chatboat", chatboat)
graph_builder.add_edge(START, "chatboat")
graph_builder.add_edge("chatboat", END)
def compile_graph_with_checkpointer(checkpointer):
return graph_builder.compile(checkpointer=checkpointer)
DB_URI = "mongodb://admin:admin@localhost:27017"
with MongoDBSaver.from_conn_string(DB_URI) as checkpointer:
graph_with_checkpointer = compile_graph_with_checkpointer(checkpointer)
config = {
"configurable": {
"thread_id": "payal"
}
}
for chunk in graph_with_checkpointer.stream(
State({"messages": ["You know that I am learning LangGraph"]}),
config,
stream_mode="values"
):
print(chunk["messages"][-1])
Example output:
AI: That is great. Learning LangGraph helps in building structured AI workflows.
Explanation:
The important part is thread_id.
It works like a user session ID.
LangGraph saves the workflow state in MongoDB under that thread.
If you run the graph again with the same thread_id, it resumes from stored memory.
This is powerful for building AI agents that remember conversations.
What Actually Gets Stored
When a checkpoint is created, MongoDB stores:
Current state values
Which node should run next
Metadata
Any errors from previous runs
So if your server crashes in the middle of execution, you can restart and continue safely.
This is similar to saving request progress in backend systems.
Why This Matters for Developers
As full stack developers, we think about:
Sessions
Databases
Recoverability
Fault tolerance
Checkpointing brings the same mindset into AI workflows.
Instead of stateless LLM calls, you get structured, recoverable agent systems.
It feels less like random prompts and more like real system design.
Closing Thoughts
When learning AI, it is tempting to focus only on models.
But real applications need structure, memory, and persistence.
Checkpointing in LangGraph is one small but important step toward building production-ready AI systems.
Learn it slowly.
Understand state clearly.
Treat AI workflows like backend architecture.
Strong foundations matter.




