A telehealth client ran video visits through a web application that already supported two commercial video APIs. They wanted to add a third provider: an open source SFU they host themselves. From the open source WebRTC media servers available, they chose mediasoup, which runs as a library inside a Node.js application and leaves signaling to the developers.

Through WebRTC staff augmentation, four WebRTC.ventures engineers joined the client’s team for ten months to build it: the media server, a browser SDK, and an adapter that plugs into the existing web application next to the two commercial providers.

Read the full Story of Success: A Self-Hosted mediasoup WebRTC Media Server for a Multi-Provider Telehealth Platform

Why Run an Open Source SFU Alongside a CPaaS

A CPaaS runs the media servers, relays and client SDKs for you, priced per participant minute. Bringing that layer in-house involves two separate choices.

  • Self-hosting puts the media servers on your own infrastructure. You decide where calls run, how nodes are deployed and taken down for maintenance, and how the media layer connects to the rest of your platform.
  • Open source gives you the code. You can tune codecs, change how video quality adapts to the network, and fix problems on your own schedule.

This project used both. Owning the stack let the team add VP9 and AV1 with scalable video coding, rank H264 profiles for hardware encoders, build its own network adaptation, connect each media node to the client’s platform message bus, and cordon nodes before maintenance so calls in progress keep running while new calls go to other nodes.

Running a self-hosted SFU next to a CPaaS also lets a platform route a share of call traffic to its own media server first and move more workflows over time. Our client planned that kind of phased rollout.

5 Lessons from Adding an Open Source SFU Next to a CPaaS

Here’s what the project taught us that applies to any team thinking about adding a self-hosted SFU to a CPaaS-based application.

Put Every Provider Behind One Interface

The client’s web client already loaded each video provider through a shared adapter interface, the pattern we describe in How to Incorporate a CPaaS Abstraction Layer in WebRTC Applications. That made the mediasoup provider a third adapter, so the applications built on top could run a call on any of the three providers.

If your app calls a single CPaaS SDK directly, adding that layer is the first step toward any second provider, self-hosted or commercial.

Leave Feature Parity for Last

Users should get the same call whichever provider carries it: screen sharing, background effects, data messaging, speaking indicators and session refresh. Matching two mature commercial integrations this closely was one of the hardest parts of the project.

The client scheduled parity work for the final months, after the core server and SDK were stable. Closing gaps late meant changing a few implementations. Chasing parity from the start would probably have slowed the core work more.

Plan for mediasoup Reconnects from Day One

Reconnect handling took a large share of the work on both the server and the client. The causes ranged from WebSocket drops and UDP blocking to laptops waking from sleep. We built three layers of recovery:

  • ICE restart and transport recovery
  • A fast reconnect that resumes the same session over a new WebSocket
  • A full rejoin (transport and websocket)

Idempotent signaling made this safe. The server runs a retried request at most once, so the SDK can queue requests while the socket is down and resend them when it comes back.

Add Your Own Adaptation on Top of the Browser’s

Browser congestion control and simulcast were not enough on their own. Chrome kept sending through moderate packet loss, and the repair traffic froze video for viewers. We added adaptation at both ends of the call:

  • Receive side: the media node caps each viewer’s video layers by network quality and recovers slowly to avoid flip-flopping. The client requests the layer each video tile needs and pauses hidden tiles.
  • Publish side: a bitrate guard pauses outgoing video when the uplink can’t carry it, and a loss throttle lowers the camera’s bitrate while the uplink loses packets.

Make Network Bugs Reproducible

Network problems are hard to reproduce by hand. Together with the client’s engineers, we built an A/V test harness that runs the real web client in headless Chrome, applies packet loss, bandwidth caps and outages through Chrome’s network emulation, and ends each run with pass/fail checks.

Every command outputs JSON, so an AI coding agent can turn a bug report into a failing scenario and confirm the fix. Many QA bugs shipped with a harness scenario alongside the fix.

Weighing an Open Source SFU Against Your CPaaS?

Whether you’re adding a self-hosted SFU next to a CPaaS, moving off one entirely, or making calls hold up on poor networks, our engineers can work independently or join your team through WebRTC staff augmentation.

Read the full Story of Success, then contact us today to talk about your project.

Further Reading:

Recent Blog Posts