WebRTC Relays for Multiplayer Games
Multiplayer games require low-latency to provide seamless gaming experiences. Traditionally, game backends have relied on centralized servers or peer-to-peer networks for player connectivity. However, it has heavy limitations and serious security and privacy issues that limit its use for commercial multiplayer games.
WebRTC (Web Real-Time Communication) relays are an alternative, particularly for smaller multiplayer games.
In this article, we’ll explore how WebRTC relays work, why they are used, why they may not be suitable for large-scale commercial games, and an alternative solution.
How WebRTC Relays for Multiplayer Games Work
WebRTC is a protocol that facilitates peer-to-peer (P2P) connections, enabling real-time audio, video, and data transfer between devices.
Like all Relays, WebRTC relays are used when a direct P2P connection between players is not feasible due to network restrictions like firewalls or NATs (Network Address Translators). In these cases, the data is relayed through a server, acting as a middleman to route traffic between players.
In multiplayer games, this system allows for the transfer of game data between players without the need for a centralized game server. Instead of routing all traffic through a single game server, WebRTC relays offload some of that responsibility by allowing direct communication, while still using servers for difficult connections.
The game’s architecture must be adapted to work with WebRTC, including managing relay servers and handling edge cases where P2P connections are impossible.
Why Use WebRTC for Multiplayer Game Backends?
Cost Efficiency: For smaller games with fewer players, WebRTC can be a cost-effective solution, reducing the need for dedicated game servers by offloading traffic to P2P networks.
Cross-Platform Support: WebRTC supports various platforms, allowing seamless connectivity across different devices, whether on a desktop, mobile, or console.
Privacy & NAT: As a single public IP is often shared among multiple users (see “What is peer-to-peer networking in multiplayer games”), relays shield this information to protect the player’s IP and the server routes the game data between players, bypassing firewalls and NAT barriers to ensure smooth communication.
Why WebRTC Relays Should Not Be Used for Commercial Multiplayer Games
While WebRTC offers several benefits, there are significant drawbacks when scaling it to larger, commercial multiplayer games:
The Hidden Development & Infrastructure Costs: Building and maintaining custom relay servers for WebRTC is expensive. Developers like People Can Fly (in their game Outriders, per their Unreal conference) have had to modify game code significantly to make WebRTC relays work within the Unreal engine. This infrastructure requires ongoing costs in hosting, testing, and optimization.
Performance Limitations: Despite reducing server costs, WebRTC relays do not always provide better performance than traditional centralized servers. For example, EOS (Epic Online Services) relays have been compared to WebRTC relays, and it’s unclear if the latter is more efficient in handling large-scale game traffic.
Security and Control: Relaying sensitive game data through external servers can pose security risks. Centralized servers offer greater control over game data and user interactions. Even if they are more secure than P2P network, unproperly implemented WebRTC relays traffic can be intercepted with tools such as Fiddler.
Increased Complexity: Customizing your game to work with WebRTC requires a deep understanding of networking protocols, custom code implementations, and extensive testing, which can be a barrier for larger game studios trying to launch on time.
The Alternative Solution: Commercial Relays
For developers looking for a free solution, Epic Online Services (EOS) and Steamworks provides free relays for developers. However, these free relay server introduces additional latency by adding an extra step for game packets, and with limited relay options, players may be routed to distant servers, causing unacceptably high latency for commercial games.
Additionally, these free relays can be vulnerable in peer-to-peer games, as tools like Fiddler allow easy access to lobby data, exposing players' private information in plain text. This security flaw can be exploited with minimal effort, making it possible for anyone to scrape and misuse player data.
For developers looking for a scalable solution, Edgegap offers an alternative to WebRTC relays with its distributed relay infrastructure. Edgegap’s distributed relays uses a network of distributed nodes located close to players, ensuring that game data is relayed through the most efficient route possible. This drastically reduces latency while offering superior scalability for commercial multiplayer games.
Edgegap’s solution is particularly attractive for games that want to offload the burden of building custom infrastructure.
Instead of managing your own WebRTC relays, Edgegap’s distributed nodes automatically select the optimal relay server for each session, reducing the need for significant infrastructure investment. This ensures higher performance, especially in regions where P2P connections may be unreliable.
Conclusion
WebRTC relays can be an efficient solution for smaller multiplayer games, offering reduced latency and simplified infrastructure.
However, they come with significant drawbacks in development and operations cost, complexity, and scalability, making them less suitable for large-scale commercial games.
For developers looking to scale efficiently while maintaining low latency, Edgegap’s distributed relay solution provides a robust alternative, combining the benefits of WebRTC’s low-latency communication with the scalability of a distributed infrastructure.
---
For more information on the comparison between Peer-to-Peer Networking, Relays and Authoritative Severs (often called Dedicated Servers), check out our dedicated breakdown on our blog.
---
The information above comes from a presentation done by Michal Buras, Senior Developer at Highwire Games, at the Live Service Game Summit conference.
A full version of this conference can be found here: Peer-to-Peer, Relays & Container Instances: And In-Depth Analysis of Development Resources, Performance, Security Issues for Multiplayer Games