AboutBlogContact
Backend EngineeringMarch 20, 2019 3 min read 190Updated: June 22, 2026

WebRTC: Scaling P2P Mesh Networking for Real-time Video (2019)

AunimedaAunimeda
📋 Table of Contents

WebRTC: Scaling P2P Mesh Networking for Real-time Video

In 2019, video chat is no longer a luxury feature; it's a standard requirement for many apps. But building a video infrastructure is expensive. The common approach is to use an SFU (Selective Forwarding Unit) or an MCU (Multipoint Control Unit)-dedicated servers that handle all the media streams.

But what if you don't have the budget for a server farm? In 2019, we're looking at WebRTC Mesh Networking.

What is a Mesh Network?

In a WebRTC mesh network, every participant connects directly to every other participant. There is no central media server. Each participant sends their stream to $N-1$ other participants and receives $N-1$ streams.

The Problem: $N^2$ Complexity

The bandwidth and CPU requirements of a mesh network grow quadratically ($O(N^2)$). For a 3-person call, it's fine. For 4 people, it starts to lag. By 6-8 people, it becomes unusable for most users.

Practical Example: Establishing a Connection

The most difficult part of WebRTC in 2019 is the signaling process-how two peers find each other. We use a "Signaling Server" (usually over WebSockets) to exchange SDP (Session Description Protocol) and ICE Candidates.

// A simple peer-to-peer setup with an RTCPeerConnection
const configuration = { iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] };
const pc = new RTCPeerConnection(configuration);

// Add local stream
const localStream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true });
localStream.getTracks().forEach(track => pc.addTrack(track, localStream));

// ICE Candidate exchange
pc.onicecandidate = ({ candidate }) => {
  if (candidate) {
    sendToSignalingServer({ type: 'candidate', candidate });
  }
};

// Handle remote stream
pc.ontrack = (event) => {
  const [remoteStream] = event.streams;
  remoteVideo.srcObject = remoteStream;
};

// Create an offer
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);
sendToSignalingServer({ type: 'offer', offer });

Optimizing Mesh Performance

To make mesh networks work in 2019, we use several tricks:

  1. Bitrate Scaling: Lowering the video resolution and bitrate as the number of participants increases.
  2. Audio Dominance: Only subscribing to the video of the active speaker.
  3. VP9 and AV1: Exploring more efficient codecs to reduce bandwidth usage.

WebRTC mesh is the "democratic" way to build real-time communication. It's decentralized and cost-effective. While it won't replace massive SFUs for large webinars, for small teams and direct 1-on-1 calls, it is a powerful and viable solution in 2019.


Aunimeda builds production-grade backend systems - APIs, microservices, real-time applications, and system integrations.

Contact us for backend engineering services. See also: Custom Software Development, Web Development

Read Also

Bun: SQLite and the Power of Zero-Overhead FFI (2023)aunimeda
Backend Engineering

Bun: SQLite and the Power of Zero-Overhead FFI (2023)

Bun isn't just a fast runtime; its native SQLite implementation and FFI are changing how we think about Node.js performance in 2023.

Deno: Ryan Dahl's Fix for Node.js (2018)aunimeda
Backend Engineering

Deno: Ryan Dahl's Fix for Node.js (2018)

The creator of Node.js just announced Deno at JSConf EU. It's a secure, Rust-based runtime that leaves 'node_modules' behind.

eBPF: In-Kernel Programmability for Networking and Security (2018)aunimeda
Backend Engineering

eBPF: In-Kernel Programmability for Networking and Security (2018)

Linux 4.x is changing the game with eBPF. Why write kernel modules when you can run safe, verified bytecode directly in the kernel?

Need IT development for your business?

We build websites, mobile apps and AI solutions. Free consultation.

Get Consultation All articles