Building an Open-Source SBC with Kamailio and rtpengine
A session border controller (SBC) sits at the edge of a voice network and handles the jobs that raw SIP servers should not: hiding internal topology, normalizing messages between incompatible systems, enforcing security policy, and anchoring media. Commercial SBCs do this well, and they are priced accordingly.
For many platforms, an open-source SBC built from Kamailio and rtpengine is a practical alternative. It is a common pattern in carrier and SaaS telephony, and it is worth understanding what you are signing up for.
The Two Building Blocks
Kamailio: the signaling layer
Kamailio is a high-performance open-source SIP server. In an SBC role it acts as a stateful SIP proxy. It receives requests from the outside, applies logic written in its routing script, and forwards them to internal systems. Its strengths are speed, a rich module ecosystem, and flexible routing logic.
Typical SBC functions implemented in Kamailio:
- Topology hiding, so external parties never see internal addresses
- Authentication and access control, including IP allow-lists and digest authentication
- Rate limiting and flood protection, using modules such as pike and htable
- Load balancing and failover across internal FreeSWITCH or Asterisk nodes, using the dispatcher module
- Header manipulation and normalization for carriers with quirks
- Routing by dialed number, source, or tenant, including least-cost decisions
rtpengine: the media layer
Kamailio handles signaling only; it does not touch audio. rtpengine is an open-source media proxy that relays RTP so that media flows through your controlled address rather than directly between endpoints. Kamailio talks to it through the rtpengine module, instructing it when to start and stop relaying a call.
What rtpengine adds:
- Media anchoring and NAT traversal, which fixes many one-way audio cases
- Transcoding between codecs where needed
- SRTP and DTLS handling, so you can encrypt on one side and use plain RTP on the other
- Interworking between WebRTC and traditional SIP endpoints
- Optional packet-forwarding in the Linux kernel for high throughput
How They Fit Together
A simplified call flow looks like this:
- A SIP INVITE arrives at Kamailio from a carrier or customer.
- Kamailio authenticates or allows the source, checks rate limits, and decides the destination.
- Kamailio asks rtpengine to rewrite the SDP so media is anchored through rtpengine.
- Kamailio forwards the INVITE to an internal node, such as FreeSWITCH, chosen by the dispatcher.
- Audio then flows through rtpengine, while signaling continues through Kamailio for the life of the call.
This separation of signaling and media lets each scale independently. For scaling patterns on the media side, see FreeSWITCH horizontal scaling with Kamailio.
Where an Open-Source SBC Excels
- Cost and flexibility. No per-session license fees, and you can implement exactly the routing logic you need.
- Scale. Kamailio is capable of handling very large registration and call-setup rates when configured well.
- Integration. Routing decisions can query your own databases and APIs, which suits multi-tenant platforms and custom billing.
- WebRTC. Combining Kamailio with rtpengine is a common way to bridge browser clients into SIP infrastructure.
Where It Falls Short
- You build and maintain it. The routing script is code that needs testing and version control.
- Carrier certification and support. Some carriers or enterprises require a specific certified SBC vendor.
- Built-in features. Commercial SBCs ship with polished management interfaces, extensive interoperability profiles, and vendor support. You assemble equivalents yourself.
- Security responsibility. You must harden the edge, keep software patched, and monitor for attacks, which is a significant ongoing commitment.
Design Considerations Before You Build
- High availability. Run at least two Kamailio instances with a floating IP or DNS-based failover, and multiple rtpengine nodes, so a single failure does not drop calls. See VoIP disaster recovery and failover design.
- Capacity planning. Size rtpengine for the media load, since it carries every audio packet. Test it, as covered in SIP trunking load testing and concurrency.
- Security. Rate limit aggressively, restrict by IP where possible, use TLS, and monitor for scanning and toll-fraud attempts.
- Observability. Capture SIP traces and metrics from day one so you can troubleshoot.
- Encryption policy. Decide which legs use TLS and SRTP. See RTP and SRTP voice encryption explained.
For a vendor-neutral look at how SBC responsibilities divide, read our overview of session border controller architecture.
Build, Buy, or Hybrid?
If you operate a carrier-style platform, run multi-tenant telephony, or need custom routing logic, an open-source SBC is often the right foundation. If you are an enterprise that needs certified interoperability with a specific PBX or carrier and prefers vendor support, a commercial SBC may be worth the license. Some organizations use a commercial SBC at the customer edge and open-source components internally.
Designing or hardening a SIP edge? Our Kamailio load balancing and SBC engineering team builds highly available Kamailio and rtpengine deployments, and our FreeSWITCH engineering team builds the media tier behind them.
Related Services
Keep Reading
Discussion
0Join 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.
Controva LLC
Engineering Team
We build digital empires that scale. Specializing in high-performance web architecture, AI automation, and headless commerce.
Work with us