Scale Horizontally with Sessions
Run many instances behind a load balancer.
Scale Horizontally with Sessions is a free MCP Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the MCP Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
One Box Has Limits
A single server process can only do so much. To serve far more traffic, you run many instances of it side by side. 📈
Scale Out, Not Just Up
Adding more copies of your server is horizontal scaling. It is often cheaper and safer than buying one ever-bigger machine.
A Load Balancer Up Front
A load balancer sits in front and spreads incoming requests across your instances, so no single copy gets overwhelmed.
HTTP Makes This Possible
Horizontal scaling needs a network transport, so MCP servers run over Streamable HTTP rather than the local-only stdio transport.
Sessions Track Each Client
MCP keeps per-client state in a session, identified by a session id the client sends back on every follow-up request.
Mcp-Session-Id: 1f5c...e9The Stickiness Problem
If a session lives only in one instance's memory, a request routed elsewhere loses its state. That mismatch is the stickiness problem.
Option A: Sticky Routing
One fix is sticky sessions: the load balancer always sends a given session id back to the same instance that created it.
Option B: Shared Session Store
Better for scale is a shared store like Redis. Any instance can load a session, so requests route freely and survive restarts.
Aim for Stateless Instances
Keep instances stateless, holding nothing critical only in local memory. Then you can add, remove, or replace them at any time.
Health Checks Guide Routing
The balancer pings each instance's health endpoint and stops sending traffic to any copy that fails, keeping users on healthy ones.
Autoscale to Demand
With stateless instances, you can autoscale: add copies when load rises and remove them when it falls, paying only for what you use.
Quick Check
What lets you route any request to any instance?
Recap: Scale Out
You ran many instances behind a load balancer, shared sessions in a central store, and kept copies stateless to autoscale on demand. 🚀
Frequently asked questions
Is the “Scale Horizontally with Sessions” lesson free?
Yes — the full text of “Scale Horizontally with Sessions” is free to read here on the web, and the MCP Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the MCP Academy course, upgrade to CoddyKit PRO.
What will I learn in “Scale Horizontally with Sessions”?
Run many instances behind a load balancer. You practise MCP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start MCP Academy?
No prior experience is required. MCP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Scale Horizontally with Sessions” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this MCP Academy lesson?
Yes. Every MCP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Async Tools That Don't Block
- Concurrency & Backpressure
- Trim Token-Heavy Results
- Scale Horizontally with Sessions