WebRTC Server: What It Is & When You Need One
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
This article explains what a WebRTC server is, the different roles it plays in a WebRTC deployment, and when you actually need one versus when you can rely on peer-to-peer connections. You’ll learn about the three main server types—signaling, STUN/TURN, and media servers—and get practical guidance for choosing the right setup for your application.
Background: The Core Misconception
WebRTC (Web Real-Time Communication) is often described as a peer-to-peer technology, which leads many people to believe that no server is involved. That is only half true. The actual media—audio and video—can flow directly between two browsers, but that flow cannot start without a signaling server. Both peers need to exchange session descriptions (SDP) and network candidates (ICE) before any media packet is sent. That exchange requires a server to relay the messages.
So when someone says “WebRTC doesn’t need a server,” they are usually referring to the media path. A server is almost always required for the control path. The term “WebRTC server” is not a single standard component; it is an umbrella term covering several distinct server-side pieces that work together.
Signaling Server: The Essential Coordinator
The signaling server is the minimum requirement for any WebRTC application. Its job is to exchange metadata between peers: session descriptions (offer/answer) and ICE candidates. It does not handle the audio or video data itself.
There is no mandated protocol for signaling. WebSocket is the most common choice, but you could use HTTP polling, Server-Sent Events, or even email. The server simply needs to relay messages between the two peers. A typical flow looks like this:
- Peer A creates an offer (SDP) and sends it to the signaling server.
- The server forwards the offer to Peer B.
- Peer B creates an answer and sends it back through the server.
- Both peers exchange ICE candidates through the server until a direct connection is established.
Once the connection is up, the signaling server is no longer involved in the media path. It may still be used for chat messages, presence, or call control, but it is not carrying the audio/video.
STUN and TURN Servers: Traversing NATs and Firewalls
Most devices sit behind a NAT (Network Address Translation) or a firewall. To establish a direct peer-to-peer connection, each peer needs to discover its public IP address and port. That is the job of a STUN (Session Traversal Utilities for NAT) server.
STUN is a lightweight protocol: the client sends a request to the STUN server, and the server replies with the public IP and port it saw. This allows the client to generate correct ICE candidates. STUN servers are stateless and can handle many users with minimal resources. Public STUN servers exist (for example, Google’s), but for production you’ll likely run your own or use a managed service.
However, STUN does not work in all cases. Some NATs are symmetric, meaning the port mapping changes per destination. In those cases, a direct connection fails. TURN (Traversal Using Relays around NAT) is the fallback. A TURN server relays all media traffic between peers. It is effectively a media relay that guarantees connectivity when direct paths fail.
TURN is expensive because it carries the actual audio/video bandwidth. You should only use it when STUN fails. In practice, a robust WebRTC deployment includes both: try STUN first, and fall back to TURN only when needed.
Media Server: When You Need More Than Two Peers
For simple one-to-one calls, a media server is not required. But as soon as you need group calls, recording, streaming, or mixing, you need a media server. There are two main architectures:
- SFU (Selective Forwarding Unit): The server receives each participant’s media stream and forwards it to the others. It does not mix or process the streams. This is the most common architecture for group video calls (used by Zoom, Google Meet, etc.) because it balances bandwidth and CPU.
- MCU (Multipoint Control Unit): The server mixes all streams into a single composite stream and sends it to each participant. This requires heavy processing but reduces bandwidth on the client side. MCU is less common now because SFU scales better.
Media servers also enable features like recording, transcoding, and broadcasting to a large audience. If you need to stream a call to thousands of viewers, you’ll typically feed the media server into a CDN or a streaming protocol like HLS.
How to Choose: When Do You Actually Need One?
The answer depends on your use case. Here is a practical breakdown:
- One-to-one calls: You need a signaling server and a STUN server. You may need a TURN server if your users are behind restrictive NATs. No media server required.
- Group calls (3+ participants): You need a media server (SFU is typical) to relay streams efficiently. You also need signaling and STUN/TURN.
- Recording or broadcasting: You need a media server that can record or transcode the streams.
- Large-scale streaming: You need a media server plus a CDN or a streaming protocol to distribute the stream to many viewers.
For a small prototype, you can start with a public STUN server and a simple WebSocket signaling server. For production, you should host your own STUN/TURN and media servers, or use a managed WebRTC platform that provides these components as a service.
Common Problems and Misconceptions
One common mistake is assuming that STUN is enough. In real-world networks, especially corporate or mobile networks, a significant percentage of connections fail without TURN. Always plan for TURN as a fallback.
Another misconception is that a media server is optional for group calls. Without an SFU, each participant sends their stream to every other participant. This creates a mesh network where each client uploads N-1 streams. For 4 participants, each sends 3 streams; for 10, each sends 9. That quickly saturates upload bandwidth and CPU. An SFU avoids this by forwarding a single stream from each participant to all others.
Security is also a concern. WebRTC is encrypted by default (DTLS and SRTP), but the signaling server can be a weak point. If you don’t use HTTPS/WSS, an attacker could intercept or modify the signaling messages. Always use secure WebSocket (WSS) for signaling.
Costs and Alternatives
Running your own servers gives you full control but requires infrastructure and maintenance. STUN servers are cheap to run because they are stateless. TURN servers are expensive because they relay high-bandwidth media. Media servers are CPU-intensive, especially if you do transcoding or mixing.
Alternatives include managed WebRTC platforms (like Twilio, Agora, or Daily) that handle signaling, TURN, and media servers for you. These are easier to start with but can become costly at scale. Open-source options like Janus, Jitsi, or mediasoup let you self-host media servers with more flexibility.
For signaling, you can build your own WebSocket server or use a managed service. For STUN/TURN, you can use open-source software like coturn. The choice depends on your team’s expertise, budget, and scaling needs.
Frequently Asked Questions
Do I need a WebRTC server for a simple video chat?
Yes, you need at least a signaling server and a STUN server. The signaling server is required to exchange session descriptions and ICE candidates. STUN is needed to discover your public IP. Without these, the two browsers cannot establish a connection.
What is the difference between STUN and TURN?
STUN is a lightweight protocol that helps a client discover its public IP and port, enabling direct peer-to-peer connections. TURN is a relay protocol that forwards media traffic when direct connections fail. TURN is more resource-intensive because it carries the actual audio/video data.
Can I use a public STUN server for production?
You can, but it is not recommended for large-scale or commercial applications. Public STUN servers are often rate-limited and may not be reliable. Running your own STUN server is inexpensive and gives you better control and reliability.
Is a media server required for group calls?
Yes, for any group call with more than two participants, a media server (typically an SFU) is necessary. Without it, each participant would have to send their stream to every other participant, which quickly overwhelms bandwidth and CPU.
What is the best open-source WebRTC server?
There is no single “best” because it depends on your needs. For media servers, Janus, Jitsi Videobridge, and mediasoup are popular choices. For TURN, coturn is the standard. For signaling, you can use any WebSocket server, such as Socket.IO or a custom Node.js server.
Does WebRTC work without a TURN server?
It can, but not always. TURN is only needed when a direct connection fails due to NAT or firewall restrictions. In many cases, STUN is enough, but you should include TURN as a fallback to ensure connectivity for all users.
Related
Formula used
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.