advanced⏱40 minutesLesson 1 of 10

Deployment

Deploy LangGraph applications with LangGraph Cloud/Platform, configure graph APIs, manage deployment options, and scale for production.

Deployment

Deploying LangGraph applications to production requires understanding LangGraph Cloud (Platform), API configuration, authentication, scaling, and operational considerations.


LangGraph Cloud / Platform Overview

LangGraph Platform provides a managed deployment infrastructure for LangGraph applications:

FeatureDescription
Managed APIAutomatic REST API generation from your graph
ScalingAuto-scaling based on demand
PersistenceManaged PostgreSQL for checkpointing
AuthenticationAPI key and OAuth support
MonitoringBuilt-in LangSmith integration
StreamingServer-Sent Events (SSE) for real-time output

Deployment Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Client │────▢│ LangGraph │────▢│ LLM β”‚ β”‚ (App/Web) β”‚ β”‚ Platform β”‚ β”‚ APIs β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ PostgreSQL β”‚ β”‚ LangSmith β”‚ β”‚ (State/Pers.)β”‚ β”‚ (Observ.) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Graph API Configuration

Create a langgraph.json configuration file at your project root:

json
{ "name": "my-agent", "version": "1.0.0", "graphs": { "agent": "./src/agent.py:graph" }, "dependencies": { "pip": ["langchain-openai", "tavily-python"], "python": "3.11" }, "env": { "OPENAI_API_KEY": "sk-...", "TAVILY_API_KEY": "tvly-..." }, "checkpointer": { "type": "postgres", "url": "postgresql://user:pass@host:5432/langgraph" } }
πŸ“ŒImportant

The graphs field maps endpoint names to Python import paths. The value "./src/agent.py:graph" means "import graph from src/agent.py".


Dockerfile Deployment

For custom deployments, use the official LangGraph Docker image:

dockerfile
FROM langchain/langgraph:latest WORKDIR /app COPY pyproject.toml . RUN pip install -e . COPY . . # The graph is auto-detected from langgraph.json EXPOSE 8080 CMD ["langgraph", "serve"]

Deployment Options

Option 1: LangGraph Cloud (Managed)

bash
# Install CLI pip install langgraph-cli # Deploy to LangGraph Cloud langgraph deploy --project my-agent # Set environment variables langgraph secrets set OPENAI_API_KEY sk-...

Option 2: Self-Hosted Docker

bash
# Build the Docker image docker build -t my-agent . # Run with environment variables docker run -p 8080:8080 \ -e OPENAI_API_KEY=sk-... \ -e DATABASE_URL=postgresql://... \ my-agent

Option 3: Kubernetes

yaml
apiVersion: apps/v1 kind: Deployment metadata: name: langgraph-agent spec: replicas: 3 selector: matchLabels: app: langgraph-agent template: metadata: labels: app: langgraph-agent spec: containers: - name: agent image: my-agent:latest ports: - containerPort: 8080 env: - name: OPENAI_API_KEY valueFrom: secretKeyRef: name: api-keys key: openai-key - name: DATABASE_URL valueFrom: secretKeyRef: name: db-credentials key: url
ℹ️Note

For production, use Kubernetes secrets or a vault service for API keys. Never hardcode secrets in your code or config files.


API Endpoints

LangGraph Platform generates these REST endpoints:

EndpointMethodDescription
/threadsPOSTCreate a new conversation thread
/threads/{id}/runsPOSTInvoke the graph on a thread
/threads/{id}/stateGETGet thread state
/threads/{id}/statePATCHUpdate thread state
/threads/{id}/runs/{run_id}/streamGETStream execution events

Client Example

python
import requests API_URL = "https://my-agent.langgraph.app" # Create a thread resp = requests.post(f"{API_URL}/threads", json={}) thread_id = resp.json()["thread_id"] # Invoke the graph resp = requests.post( f"{API_URL}/threads/{thread_id}/runs", json={"input": {"query": "What is LangGraph?"}} ) print(resp.json()) # Get state state = requests.get(f"{API_URL}/threads/{thread_id}/state") print(state.json())

Streaming from Deployed API

python
# Stream events via SSE import json import requests with requests.post( f"{API_URL}/threads/{thread_id}/runs/stream", json={"input": {"query": "Write a poem"}}, stream=True ) as resp: for line in resp.iter_lines(): if line: event = json.loads(line.decode("utf-8").removeprefix("data: ")) print(event)

Authentication

python
# API Key authentication headers = { "X-Api-Key": "lgv2_...", "Content-Type": "application/json" } resp = requests.post( f"{API_URL}/threads", headers=headers, json={} )
⚠️Warning

Rotate API keys regularly. Use short-lived keys for production and revoke compromised keys immediately.


Scaling Considerations

DimensionStrategy
Concurrent usersHorizontal scaling (more replicas)
Long-running graphsAsync execution with webhook callbacks
DatabasePostgreSQL connection pooling (PgBouncer)
LLM rate limitsQueue requests, implement retry with backoff
MemoryMonitor checkpoint size, trim old checkpoints
Cold startsKeep minimum replicas warm

Database Connection Pooling

python
from langgraph.checkpoint.postgres import PostgresSaver # Use connection pooling for production checkpointer = PostgresSaver.from_conn_string( "postgresql://user:pass@host:5432/langgraph", pool_size=10, max_overflow=20 )

Health Checks

python
from fastapi import FastAPI from langgraph.graph import StateGraph app = FastAPI() graph_app = builder.compile(checkpointer=checkpointer) @app.get("/health") def health(): return {"status": "ok", "graph": "ready"} @app.post("/invoke") def invoke(input: dict): result = graph_app.invoke(input) return result

Practice Questions

Practice Question

What file configures LangGraph Platform deployment?

Practice Question

What does the 'graphs' field in langgraph.json specify?

Practice Question

What database is recommended for production checkpointing?

Practice Question

Which HTTP method creates a new conversation thread?

Practice Question

How do you invoke a graph on an existing thread via the API?

Practice Question

How should secrets be handled in production LangGraph deployments?

Practice Question

What is a recommended strategy for LLM rate limits in production?

Practice Question

How does LangGraph Platform handle concurrent users?

Practice Question

What protocol does LangGraph Platform use for real-time streaming?

Practice Question

What information does a health check endpoint typically return?


βœ…Success

Key Takeaways

  • langgraph.json configures LangGraph Platform deployment
  • Three deployment options: LangGraph Cloud, self-hosted Docker, Kubernetes
  • REST API: POST /threads β†’ POST /threads/{id}/runs β†’ GET /threads/{id}/state
  • PostgreSQL for production checkpointing; connection pooling for scale
  • API key authentication with regular rotation
  • Horizontal scaling for concurrent users; retry with backoff for rate limits
  • SSE for real-time streaming of execution events and tokens
  • Health checks for monitoring and orchestration
Progress10%