Skip to content
gentic.news — AI News Intelligence Platform
Connecting to the Living Graph…

Listen to today's AI briefing

Daily podcast — 5 min, AI-narrated summary of top stories

Engineer at a server rack adjusting network cables while a diagram on a monitor illustrates MCP session migration…
Open SourceScore: 95

Scale MCP for Production: How to Avoid Sticky Sessions with External State

Scale MCP without sticky sessions: store state in Redis/Postgres, add a gateway, and use Streamable HTTP. Your Claude Code MCP servers will survive container restarts and load balancers.

·17h ago·3 min read··20 views·AI-Generated·Report error
Share:
Source: dev.tovia devto_mcp, reddit_claude, devto_claudecode, hn_claude_code, lovable_blog_gnWidely Reported
How do I scale MCP servers for production without sticky sessions?

Move MCP session state out of process memory into Redis or Postgres. Add a gateway for auth and routing, and use Streamable HTTP transport so any healthy server instance can handle any request.

TL;DR

Stop storing MCP session state in memory. Use Redis or Postgres to keep agent workflows alive across restarts and load balancers.

Key Takeaways

  • Scale MCP without sticky sessions: store state in Redis/Postgres, add a gateway, and use Streamable HTTP.
  • Your Claude Code MCP servers will survive container restarts and load balancers.

What Changed — MCP Session Architecture Is Moving to Stateless, Web-Native Design

5-Hello MCP: Session Management with Sticky Session | by ...

Claude Code users who run MCP servers for multi-user agent workflows have a scaling problem. A local MCP server keeps session state in memory using a simple Map. That works on your laptop. In production, behind a load balancer with multiple instances, autoscaling, and container restarts, that in-memory state disappears when the next request lands on a different server.

The industry is shifting MCP from "one client talks to one remembered server" toward a web-native architecture. The key insight: session state is data, not process memory. This isn't about removing sessions — it's about storing them externally so any healthy server instance can handle any request.

What It Means For You — Concrete Impact on Your Claude Code MCP Servers

Retire Sticky Sessions: The Load Balancer Feature That ...

If you deploy MCP servers for Claude Code (e.g., custom tools for code analysis, deployment, or database queries), you've likely encountered:

  • Tool calls failing because a container restarted
  • Uneven load distribution from sticky sessions
  • Fragile blue/green deployments where state gets lost

The fix is straightforward: move session metadata (tenant ID, user ID, allowed tools, budget limits, workflow checkpoints) to Redis, Postgres, or DynamoDB. The server process executes tool calls, but durable workflow truth lives outside it.

Try It Now — Commands, Config, and Patterns to Scale Your MCP Servers

1. Add a Gateway Layer

Don't expose every MCP server directly. Use a lightweight gateway (or API gateway) that handles:

  • Authentication
  • Tenant lookup
  • Rate limits
  • Session ID creation
  • Routing to the right MCP service

2. Use Streamable HTTP Transport

For hosted MCP servers, prefer Streamable HTTP over stdio. Each client message is an HTTP POST, and servers can return JSON or stream with SSE. Standard load balancers understand the traffic shape.

POST /mcp
Accept: application/json, text/event-stream
Mcp-Session-Id: sess_123

{ "jsonrpc": "2.0", "id": 7, "method": "tools/call", "params": {...} }

3. Store Session State Externally

Redis for hot state:

type McpSession = {
  sessionId: string;
  tenantId: string;
  userId: string;
  allowedTools: string[];
  budgetRemaining: number;
  createdAt: number;
  expiresAt: number;
  lastEventId?: string;
  status: "active" | "cancelled" | "expired";
};

Postgres for durable audit history:

create table mcp_tool_calls (
  id uuid primary key,
  session_id text not null,
  tenant_id text not null,
  user_id text not null,
  tool_name text not null,
  input jsonb,
  output jsonb,
  duration_ms integer,
  created_at timestamptz default now()
);

4. Modify Your MCP Server to Check External State

Instead of const sessions = new Map(), your server should:

  • On startup: connect to Redis/Postgres
  • On tool call: look up session by ID from external store
  • On write: update session state atomically

This ensures any healthy instance can handle any request, regardless of which server started the session.


Source: dev.to

Source: gentic.news · · author= · citation.json

AI-assisted reporting. Generated by gentic.news from multiple verified sources, fact-checked against the Living Graph of 4,300+ entities. Edited by Ala SMITH.

Following this story?

Get a weekly digest with AI predictions, trends, and analysis — free.

AI Analysis

For Claude Code users running custom MCP servers, the immediate action is to refactor your session management. Currently, most developers use in-memory maps for session state — that's the bottleneck. Switch to Redis for hot state (session identity, budget, allowed tools) and Postgres for audit logs. This change alone makes your agent workflows survive container restarts, load balancer redistributions, and autoscaling events. Next, add a gateway layer. You don't need a complex service mesh — a simple reverse proxy with middleware that creates trace IDs and looks up tenant info is enough. This centralizes auth and routing, so your MCP servers stay focused on tool execution. Finally, adopt Streamable HTTP transport for all hosted MCP servers. It uses standard HTTP POST requests that any load balancer understands, and clients can reconnect and resume sessions when supported. Claude Code users should update their CLAUDE.md or MCP server configuration files to reference external state stores. For example, add environment variables for Redis connection strings and set session TTLs that match your workflow durations. Test by restarting a server instance mid-workflow — if the next tool call succeeds without session loss, you've fixed the scaling trap.
This story is part of
Claude Code's Campus Conquest Flips Anthropic's Talent Pipeline, Leaving Google's Academic Edge in Doubt
Viral adoption at MIT and Stanford transforms Claude Code from product into recruiting funnel, threatening Google's long-held research talent dominance

Mentioned in this article

Enjoyed this article?
Share:

AI Toolslive

Five one-click lenses on this article. Cached for 24h.

Pick a tool above to generate an instant lens on this article.

Related Articles

From the lab

The framework underneath this story

Every article on this site sits on top of one engine and one framework — both built by the lab.

More in Open Source

View all