Module 5 · Streaming & production

Deploying with LangGraph Platform or your own server

6 min read

A graph that works in a script must now serve thousands of conversations, survive restarts and integrate with your applications. Two paths are open: LangChain's managed platform, which provides ready-made infrastructure, or your own server, like Relay's. This lesson presents both, and the criteria for choosing.

What an agent server must provide

Whatever the path, the same needs come back:

NeedWhy
Persistence (checkpointer + store)Memory, resumption, interrupts
Threads and runs APICreate a conversation, send a message, resume, read the state
StreamingUser experience (lesson 5.1)
Background runsLong processing without an open connection
Concurrency managementOne message at a time per thread, double-texting (lesson 5.3)
Authentication and authorizationWho can read which thread, who can approve what
ObservabilityTraces, metrics, logs

Path 1: the managed platform

LangChain offers a deployment service for LangGraph graphs, long called LangGraph Platform and integrated into LangSmith since late 2025 under the name LangSmith Deployment; its runtime server is now called Agent Server. It provides all the needs in the table above in one block: managed Postgres persistence, a complete REST API for threads and runs, streaming, scheduled runs (cron), double-texting strategies, customizable authentication, and a visualization and debugging interface (LangGraph Studio).

Deployment is described in a langgraph.json file at the project root:

{
  "dependencies": ["."],
  "graphs": {
    "relay": "./relay/platform.py:graph"
  },
  "env": ".env"
}

The platform manages the checkpointer and the store itself: so you expose a compiled graph without persistence (the companion code's relay/platform.py file):

from .graph import build_graph

graph = build_graph()

Local development uses the CLI:

pip install -U "langgraph-cli[inmem]"
langgraph dev            # local server with hot reload and access to Studio

On the client side, the langgraph-sdk (Python and JavaScript) talks to the API: creating threads, streaming runs, resuming with Command(resume=...), reading the state. Deployment can be fully managed (LangChain's cloud), hybrid, or self-hosted depending on the plan. Terms and pricing change: check them in the official documentation before committing.

Path 2: your own server

Relay's server (relay/server.py) shows that a complete server fits in about 150 lines with FastAPI:

POST /threads/{id}/messages   sends a message and streams the answer (SSE)
POST /threads/{id}/resume     answers an approval request
GET  /threads/{id}            current state: messages, status, pending approvals
GET  /threads/{id}/history    checkpoint history

Its key elements:

The lifecycle. The checkpointer, store and graph are created once, at startup, in the lifespan function, and shared by all requests. Creating a checkpointer per request would open a connection each time.

@asynccontextmanager
async def lifespan(app: FastAPI):
    async with AsyncExitStack() as stack:
        url = os.environ.get("RELAY_DATABASE_URL")
        if url:
            checkpointer = await stack.enter_async_context(AsyncPostgresSaver.from_conn_string(url))
            store = await stack.enter_async_context(AsyncPostgresStore.from_conn_string(url))
            await checkpointer.setup()
            await store.setup()
        else:
            checkpointer, store = InMemorySaver(), InMemoryStore()
        app.state.graph = build_graph(checkpointer=checkpointer, store=store)
        app.state.locks = {}
        yield

The context comes from the authenticated caller. Each request builds Context(customer_id=...). In the companion code, customer_id is a request field, to keep tests simple; in production, it must be extracted from the authentication token, never from a field the client controls.

Approvals have their own route. /resume checks that an approval is indeed pending, then resumes with Command(resume=...). Only internal roles should be able to call it.

Durability is maximal. Runs use durability="sync": each step is written before the next.

Comparing the two paths

CriterionManaged platformHomemade server
Time to productionVery shortLonger: everything must be built and operated
Ready-made featuresMany (cron, double-texting, Studio, background runs)The ones you write
ControlLimited to the platform's optionsTotal: API, data, infrastructure
CostSubscription and usageYour infrastructure and your time
DataAt the provider, except with the self-hosted planAt your place
Integration with an existing applicationThrough the APINative: same services, same authentication

One criterion often outweighs the others: where your data lives. For a regulated sector or sensitive personal data, a homemade server (or the self-hosted plan) simplifies compliance. For a small team that wants to move fast, the platform avoids reinventing infrastructure.

Good news: the graph doesn't change. Relay deploys on the platform with relay/platform.py, or in its own server with relay/server.py, from the same build_graph(). Starting with one doesn't prevent switching to the other.

The production checklist

  • Postgres persistence, with a connection pool and a retention policy.
  • Secrets (model API key, database URL) in a secrets manager, never in the code or the image.
  • Authentication on every route; the context (customer_id) derived from the token.
  • Authorization: a user only sees their own threads; only certain roles can resume an approval.
  • Recursion limit set explicitly (lesson 2.2), and timeouts on nodes calling the outside world.
  • Observability: run traces (LangSmith, or OpenTelemetry to your tool), structured logs with the thread_id, latency, cost and escalation-rate metrics.
  • A single process per instance, or a distributed lock (next lesson).
  • Automated tests run on every deployment (lesson 5.4).

Key takeaways

  • An agent server must provide persistence, a threads API, streaming, background runs, concurrency, authentication and observability.
  • The managed platform (LangSmith Deployment, formerly LangGraph Platform) provides all of that from a langgraph.json and a compiled graph without persistence.
  • A homemade FastAPI server takes little code: persistence created at startup, context from authentication, a protected resume route.
  • The graph is the same in both cases: the choice is about control, cost and data location.

Practice

  1. Run Relay's server offline (RELAY_FAKE_LLM=1 uvicorn relay.server:app), open /docs and walk through a refund request with two-level approval.
  2. Replace the requests' customer_id field with an Authorization header containing a signed token, checked by a FastAPI dependency.
  3. Install langgraph-cli[inmem], run langgraph dev in the companion code's folder, and compare the generated API with the homemade server's.

Resources