<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/building-a-proper-backend-for-my-langgraph-ai-agent-wqdf4d0cp" -->

---
title: Building a Proper Backend for My LangGraph AI Agent
description: Walks through upgrading a demo LangGraph booking agent from in-memory storage to a proper Postgres-backed persistence layer. Covers why in-memory state (a...
canonical: https://daily.dev/posts/building-a-proper-backend-for-my-langgraph-ai-agent-wqdf4d0cp
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Building a Proper Backend for My LangGraph AI Agent | daily.dev
og:description: Walks through upgrading a demo LangGraph booking agent from in-memory storage to a proper Postgres-backed persistence layer. Covers why in-memory state (a...
og:url: https://daily.dev/posts/building-a-proper-backend-for-my-langgraph-ai-agent-wqdf4d0cp
og:image: https://api.daily.dev/og/posts/WqDF4d0cP.png
og:image:alt: Building a Proper Backend for My LangGraph AI Agent
og:image:width: 1200
og:image:height: 630
og:locale: en
---

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

# Building a Proper Backend for My LangGraph AI Agent

**[Towards Data Science](https://daily.dev/sources/tds)** · 7 min read · 2 upvotes · 0 comments

## Summary

Walks through upgrading a demo LangGraph booking agent from in-memory storage to a proper Postgres-backed persistence layer. Covers why in-memory state (a LangGraph MemorySaver checkpointer plus a Python list booking repository) breaks down outside a single demo process, including lost state on restart and double-booking risk across sessions. Introduces a BookingRepository protocol so the graph can swap between InMemoryBookingRepository and PostgresBookingRepository, shows the schema (technicians and bookings tables), and walks through how graph nodes like generate_schedule_options_node and confirm_booking_node read and write through the repository. Source code is available on GitHub, with a follow-up article promised covering Docker setup and hosted Postgres.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://towardsdatascience.com/building-a-proper-backend-for-my-langgraph-ai-agent>

## Questions this post answers

### Why does an in-memory LangGraph checkpointer and booking store fail in production?

In-memory state loses all conversation checkpoints and bookings on process restart, and different sessions cannot see each other's bookings since each process keeps its own list. This can let an agent confirm a booking based on a stale view after another session already took the slot, so a shared, persistent database is needed once you move beyond a single-process demo.

_Anyone hardening an AI agent's state layer can find real-world patterns like this on daily.dev._

### How do you let a LangGraph agent switch between in-memory storage and Postgres without changing the graph logic?

Define a BookingRepository Protocol with technicians, list_bookings, and create_booking members, then implement both InMemoryBookingRepository and PostgresBookingRepository against it. At startup, create_persistence() checks whether DATABASE_URL is set and picks the Postgres repository and checkpointer, or falls back to in-memory versions, so graph nodes always call the same interface regardless of backend.

_Developers designing swappable persistence layers for agents often browse similar backend patterns on daily.dev._

## Similar posts on daily.dev

- [Connecting My LangGraph AI Agent to Postgres](https://daily.dev/posts/connecting-my-langgraph-ai-agent-to-postgres-tfjwq7jte) · Towards Data Science · 0 upvotes · 1 comments
- [Medium](https://daily.dev/posts/medium-i7sbdcdol) · Medium · 0 upvotes · 0 comments
- [I Replaced a 15-Minute Booking Process with a LangGraph AI Agent](https://daily.dev/posts/i-replaced-a-15-minute-booking-process-with-a-langgraph-ai-agent-iosigqydn) · Towards Data Science · 1 upvotes · 0 comments
- [How to Build an AI Agent with LangChain and LangGraph: Build an Autonomous Starbucks Agent](https://daily.dev/posts/how-to-build-an-ai-agent-with-langchain-and-langgraph-build-an-autonomous-starbucks-agent-ngn3fbgtm) · freeCodeCamp · 8 upvotes · 0 comments
- [The agent is not the system. Postgres is.](https://daily.dev/posts/the-agent-is-not-the-system-postgres-is--hqvmc46rn) · Planet PostgreSQL · 1 upvotes · 0 comments

---

Tags: [#python](https://daily.dev/tags/python), [#ai-agents](https://daily.dev/tags/ai-agents), [#backend](https://daily.dev/tags/backend), [#postgresql](https://daily.dev/tags/postgresql), [#langgraph](https://daily.dev/tags/langgraph)

[View this post on daily.dev](https://daily.dev/posts/building-a-proper-backend-for-my-langgraph-ai-agent-wqdf4d0cp)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Building a Proper Backend for My LangGraph AI Agent","url":"https://daily.dev/posts/building-a-proper-backend-for-my-langgraph-ai-agent-wqdf4d0cp","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/building-a-proper-backend-for-my-langgraph-ai-agent-wqdf4d0cp"},"datePublished":"2026-08-22T17:07:14.115Z","dateModified":"2026-09-13T18:56:50.351Z","description":"Walks through upgrading a demo LangGraph booking agent from in-memory storage to a proper Postgres-backed persistence layer. Covers why in-memory state (a...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/b78657106b26b3e907d776ca9d5e598d?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/b78657106b26b3e907d776ca9d5e598d?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Towards Data Science","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Towards Data Science","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/tds","url":"https://daily.dev/sources/tds"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/building-a-proper-backend-for-my-langgraph-ai-agent-wqdf4d0cp","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python,ai-agents,backend,postgresql,langgraph","timeRequired":"PT7M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Towards Data Science","item":"https://daily.dev/sources/tds"},{"@type":"ListItem","position":3,"name":"Building a Proper Backend for My LangGraph AI Agent"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/building-a-proper-backend-for-my-langgraph-ai-agent-wqdf4d0cp#faq","mainEntity":[{"@type":"Question","name":"Why does an in-memory LangGraph checkpointer and booking store fail in production?","acceptedAnswer":{"@type":"Answer","text":"In-memory state loses all conversation checkpoints and bookings on process restart, and different sessions cannot see each other's bookings since each process keeps its own list. This can let an agent confirm a booking based on a stale view after another session already took the slot, so a shared, persistent database is needed once you move beyond a single-process demo. Anyone hardening an AI agent's state layer can find real-world patterns like this on daily.dev."}},{"@type":"Question","name":"How do you let a LangGraph agent switch between in-memory storage and Postgres without changing the graph logic?","acceptedAnswer":{"@type":"Answer","text":"Define a BookingRepository Protocol with technicians, list_bookings, and create_booking members, then implement both InMemoryBookingRepository and PostgresBookingRepository against it. At startup, create_persistence() checks whether DATABASE_URL is set and picks the Postgres repository and checkpointer, or falls back to in-memory versions, so graph nodes always call the same interface regardless of backend. Developers designing swappable persistence layers for agents often browse similar backend patterns on daily.dev."}}]}
```

