How to Successfully Scale Your WebRTC Application in 2021

Scaling WebRTC applications is important if you want to utilize them for large events with heavy traffic. This article contributed by Anton Venema talks about implementing scalable WebRTC solutions.

Anton Venma

This article has been contributed by Anton Venema, CTO for LiveSwitch Inc. Anton is one of the world’s foremost experts on RTC solutions and the technical visionary and prime architect of LiveSwitch’s technology.

Introduction

“How do I scale this?”

This is a question that is asked eventually, often too late but never too early, by everyone that builds successful web-based software products.

The importance of a plan for scalability is hard to overstate, but unfortunately, it’s often left until the last moment when something has already started to fail. It’s even more important for applications that incorporate Web Real-Time Communication, or any other real-time communications technology, especially if video is an integral component.

So how do we scale WebRTC-based applications? Thankfully, it’s not that hard. You just need the right pieces in place.

How to Scale WebRTC

How to Scale WebRTC Applications

To get started, take a step back and look at how your application uses Web Real-Time Communication. Ask yourself these questions:

  1. What is the maximum number of users I need to support in a session?
  2. What is the average number of users I expect to support in a session?
  3. How many users will send media within a session?
  4. How many users will receive media within a session?
  5. Will my users typically connect from residential or corporate networks?
  6. Will my users connect in from high-security networks (e.g. hospitals)?
  7. What do I need to record, and with what guarantees?

These questions require some forethought and research, but they will help you decide on the technical architecture that most closely matches your needs. Once you know the answers, you can choose between:

  1. Mesh
  2. Forwarding
  3. Mixing
  4. Hybrid

What is a Mesh Architecture?

Mesh depends almost completely on the client’s capabilities. Each client connects directly to every other client, resulting in each client managing (n-1) bidirectional connections, where n is the total number of clients. With 3 clients in a session, each client has to manage 2 separate connections. Since each connection is encrypted uniquely, each client is responsible for encrypting and uploading their media 2 separate times.

For the math-oriented, this type of architecture can be represented as a complete graph, where each vertex is a client, and each edge is a connection. The total number of connections is exponential, equal to n * (n-1), which starts out small but adds up in a hurry.

Since most Internet connections are asymmetric (download bandwidth > upload bandwidth), upload bandwidth can become a limiting factor, especially if we’re using data-heavy video. Having to encrypt each media stream once for every connection doesn’t help, especially on mobile.

That said, mesh requires no server infrastructure beyond the requisite signaling and TURN server(s), so for applications where sessions typically involve 2-3 clients, the mesh is an excellent, low-cost approach. 

What is a Forwarding Architecture?

Forwarding depends on a selective forwarding unit, or SFU, which acts as an intelligent media relay in the middle of a session. Every client connects to the SFU once to send media, and then once more for every other client, resulting in each client managing n unidirectional connections, where n is the total number of clients. With 5 clients in a session, each client has to manage 5 separate connections. One of those connections is reserved for sending media, while the others are exclusively for receiving media.

The total number of connections in this architecture is n2. While this is more than a mesh architecture, it is far more scalable for your clients. It plays well into the asymmetric nature of most Internet connections by requiring each client to upload only once. Related to this, you are also only encrypting once, which alleviates pressure on the device itself, especially on mobile.

One of the big advantages forwarding has over a mesh architecture is that it can employ various scaling techniques. Because it acts as a proxy between the sender and receiver, it can monitor bandwidth capabilities of each leg and selectively apply temporal (frame-rate) and spatial (resolution) scaling to the packet stream as it moves through the server.

Forwarding requires additional server infrastructure (the SFUs themselves) but is highly efficient. An SFU doesn’t attempt to depacketize the stream (unless recording is activated) or decode the data.

Related:  Monitoring The Dynamic World of OTT Ad Insertion

What is a Mixing Architecture?

Mixing depends on a multipoint control unit, or MCU, which acts as a high-powered media mixer in the middle of a session. Every client connects to the MCU once, resulting in each client managing just a single bidirectional connection, regardless of the number of other clients present. The connection is used to send media to and receive a mix of media from the server.

Like forwarding, we are only encrypting and uploading once, but now we are only downloading and decrypting once as well. From the perspective of the clients, this is the most efficient approach. From the perspective of the server, this is the least efficient approach. The burden of depacketizing, decoding, mixing, encoding, and packetizing is borne entirely by the server. While there are many things that can be done to optimize this pipeline, it is still a fairly heavy set of operations that require significant server resources to complete in real-time. In addition, since video layout control is centralized, each participant sees the same view. This limits the ability to customize individual user experiences or separate out the view of yourself in the mix.

As with forwarding, mixing can take advantage of scaling techniques. By applying temporal and spatial scaling to the output of the audio and/or video mixer(s), we can adapt quickly to changing conditions along the network routes to individual clients, keeping the quality as high as possible and without affecting other clients in the session.

For applications with large numbers of active participants, like virtual classrooms, or cases where devices are particularly bandwidth- and resource-constrained, this is a great approach, albeit a potentially expensive one in terms of server cost.

What is a Hybrid Architecture?

Hybrid architectures are, as their name implies, a combination of mesh, forwarding, and/or mixing. In a hybrid environment, participants can join a session based on whatever makes the most sense for the session or even for a particular endpoint. For simple two-party calls, a mesh setup is simple and requires minimal server resources. For small group sessions, broadcasts, and live events, forwarding will better meet your needs. For larger group sessions or telephony integrations, mixing is often the only practical option.

Hardware Requirements to Scale Your WebRTC Application

No matter which architecture you choose, keep in mind that you will always need:

  1. A signaling server 
  2. A TURN server 

With a couple of signaling servers and a couple of TURN servers to support high availability, you’re looking at a minimum of 4 servers to start. You’re up to 6 servers once you throw in a load balancer and a back-end database or caching service.

When selecting your server hardware, we recommend a general-purpose or compute-optimized server for signaling and a network-optimized server for TURN. If you’re using Amazon Web Services, the M- and C-class servers are excellent choices. If you are using Azure, the A-class servers that are computed- or network-optimized are the way to go.

Now that you know the four different architectures, which one will you choose to scale your WebRTC-based application? 

Anton Venma
Anton Venema

Anton Venema is the Chief Technology Officer for LiveSwitch Inc. He is one of the world’s foremost experts on RTC solutions, as well as the technical visionary and prime architect of our technology. Anton has over a decade of experience designing, building, testing, and scaling real-time enterprise solutions across a wide range of industries, including virtual events, healthcare, education, finance, and more.

He’s passionate about making high-quality, flexible voice, video, and data streaming accessible to companies that want to deliver great interactive experiences to their customers on a wide range of platforms and devices.

LiveSwitch Inc. is the leader in high-quality, personalized video conferencing. Formerly known as “Frozen Mountain,” the company provides the most flexible live video, audio and messaging platform on the market. In 2021, the company changed its name to “LiveSwitch Inc,” as part of an expansion of their video conferencing solutions and an alignment with their flagship product line, LiveSwitch. With more than 10 years of experience and a passion for innovation, the organization prides itself on providing the best real-time communications technology on the market.

Be the first to comment

Leave a Reply

Your email address will not be published.


*