Skip to main content

Architecture: LangGraph Persistence Backends: Redis, Postgres, MongoDB

Decision​

Deploy a dedicated Redis Stack instance as the primary option, and provide PostgreSQL and MongoDB as additional backend choices for organizations with existing database infrastructure.

AlternativeProsConsDecision
Redis Stack + factory (primary)Correct modules, clean separation, fastAdditional podSelected
PostgreSQL backendACID, relational, existing infraHeavier, more setupSelected
MongoDB backendDocument-native, flexible, Atlas/DocumentDBCustom store wrapperSelected
Upgrade rag-redis to Redis StackReuse existing infraRisk to RAG indexingRejected
Keep in-memoryZero infraState lost on restartRejected

Solution Architecture​

Checkpointer Factory (checkpointer.py)​

# Environment variables:
LANGGRAPH_CHECKPOINT_TYPE=memory # memory (default) | redis | postgres | mongodb
LANGGRAPH_CHECKPOINT_REDIS_URL= # Redis Stack connection string
LANGGRAPH_CHECKPOINT_POSTGRES_DSN= # PostgreSQL DSN
LANGGRAPH_CHECKPOINT_MONGODB_URI= # MongoDB connection URI
LANGGRAPH_CHECKPOINT_TTL_MINUTES=0 # 0 = no expiry
  • create_checkpointer() returns the appropriate saver based on LANGGRAPH_CHECKPOINT_TYPE
  • get_checkpointer() provides a global singleton
  • Graceful fallback: if backend is unreachable or package missing, falls back to InMemorySaver

Store Factory (store.py)​

# Environment variables:
LANGGRAPH_STORE_TYPE=memory # memory (default) | redis | postgres | mongodb
LANGGRAPH_STORE_REDIS_URL= # Redis Stack connection string
LANGGRAPH_STORE_POSTGRES_DSN= # PostgreSQL DSN
LANGGRAPH_STORE_MONGODB_URI= # MongoDB connection URI
BackendImplementationPackage
Redis_LazyAsyncRedisStore → AsyncRedisStorelanggraph-checkpoint-redis
Postgres_LazyAsyncPostgresStore → AsyncPostgresStorelanggraph-checkpoint-postgres
MongoDB_LazyAsyncMongoDBStore (custom, motor-based)motor

Helm Chart (langgraph-redis)​

  • New subchart: charts/ai-platform-engineering/charts/langgraph-redis/
  • Image: redis:8.0-alpine (Redis 8.0+ includes RedisJSON + RediSearch natively)
  • PVC-backed persistence (2Gi default)
  • Controlled via global.langgraphRedis.enabled condition
  • Non-root container with security context hardening

Agent Wiring​

  • deep_agent.py: InMemorySaver() replaced with create_checkpointer()
  • base_langgraph_agent.py: Module-level MemorySaver() replaced with get_checkpointer() singleton

Components Changed​

Python​

  • ai_platform_engineering/utils/checkpointer.py (new) — Checkpointer factory (memory/redis/postgres/mongodb)
  • ai_platform_engineering/utils/store.py — Store factory with _LazyAsyncRedisStore, _LazyAsyncPostgresStore, _LazyAsyncMongoDBStore
  • ai_platform_engineering/multi_agents/platform_engineer/deep_agent.py — Uses create_checkpointer()
  • ai_platform_engineering/utils/a2a_common/base_langgraph_agent.py — Uses get_checkpointer()
  • pyproject.toml — Added langgraph-checkpoint-redis>=0.3.5, langgraph-checkpoint-postgres>=2.0.0, langgraph-checkpoint-mongodb>=0.3.0, motor>=3.4.0

Helm​

  • charts/ai-platform-engineering/charts/langgraph-redis/ (new) — Redis Stack subchart
  • charts/ai-platform-engineering/Chart.yaml — Added langgraph-redis dependency
  • charts/ai-platform-engineering/values.yaml — Added global.langgraphRedis.enabled, postgres/mongodb to checkpointPersistence and memoryPersistence
  • charts/ai-platform-engineering/charts/supervisor-agent/values.yaml — Added postgres/mongodb to checkpointPersistence, mongodb to memoryPersistence
  • charts/ai-platform-engineering/charts/supervisor-agent/templates/deployment.yaml — Postgres/MongoDB checkpoint and store env vars
  • charts/ai-platform-engineering/charts/agent/values.yaml — Added postgres/mongodb to checkpointPersistence
  • charts/ai-platform-engineering/charts/agent/templates/deployment.yaml — Postgres/MongoDB checkpoint env vars

Tests​

  • tests/test_checkpointer.py — 29 unit tests (config, factory, singleton for all backends)
  • tests/test_redis_store.py — 36 unit tests (Redis, Postgres, MongoDB store wrappers + factory)