Back to Insights
VoIP Engineering

Scaling FreeSWITCH Horizontally: A Guide to Clustering and Load Balancing with Kamailio

Telephony Engineering Team
8 min read
Scaling FreeSWITCH Horizontally: A Guide to Clustering and Load Balancing with Kamailio

A single FreeSWITCH instance, well-tuned, can comfortably handle a few thousand concurrent calls. Past that point — or for any deployment that can't tolerate a single point of failure — the path forward is horizontal scaling: multiple FreeSWITCH media nodes behind a Kamailio load-balancing layer. Getting there without breaking call state requires a specific architecture.

Why You Can't Just Round-Robin SIP Traffic

The naive approach — load balancing SIP INVITEs randomly across FreeSWITCH nodes — breaks almost immediately, because SIP dialogs and their associated media state are tied to whichever node first accepted the call. A registration, an in-progress call, and its BYE message all need to land on a node that actually knows about that dialog.

The Standard Pattern: Kamailio as Stateful Dispatcher

Kamailio's dispatcher module solves this by maintaining awareness of which FreeSWITCH node owns which call, and consistently routing subsequent SIP messages for that dialog to the correct node — rather than a naive load balancer that treats every packet independently.

[ SIP Trunk / Registrations ]
              │
              ▼
     [ Kamailio Cluster ]  ← stateful dispatch, registration handling
       │        │        │
       ▼        ▼        ▼
  [ FS Node 1 ][ FS Node 2 ][ FS Node 3 ]  ← media anchoring, call processing

Key Design Decisions

  • Registration state sharing — Kamailio nodes need shared registration state (via a database or in-memory cluster like usrloc replication) so a call can be routed correctly regardless of which Kamailio instance receives the initial SIP request
  • Health checking — Kamailio must actively monitor FreeSWITCH node health and remove failed nodes from rotation before routing new calls to them, without dropping calls already in progress on a degrading node
  • Media path planning — decide whether media flows directly between the caller and the assigned FreeSWITCH node, or is anchored through an rtpengine layer for additional NAT handling and recording capability

What Breaks Without This Architecture

Teams that attempt to scale FreeSWITCH horizontally without a proper dispatch layer typically discover the failure mode the hard way: mid-call transfers fail, hold/resume breaks, and any feature relying on in-dialog state (call parking, conferencing) becomes unreliable the moment traffic crosses more than one node.

Capacity Planning Per Node

Rather than maximizing calls-per-node, well-run clusters typically target 60–70% of a node's theoretical maximum concurrency, leaving headroom for traffic spikes and for the cluster to absorb a node failure without cascading overload onto the remaining nodes.


Outgrowing a single FreeSWITCH instance and need a clustering architecture that won't break mid-call? Controva LLC designs and deploys production Kamailio + FreeSWITCH clusters built for real failover, not just theoretical scale.

Discussion

0

Join the conversation

Sign in with your preferred account to comment, reply, and keep the discussion useful for other engineers.

Takes a few seconds. No separate password required.

C

Controva LLC

Engineering Team

We build digital empires that scale. Specializing in high-performance web architecture, AI automation, and headless commerce.

Work with us

Share this article