Authoritative vs peer-to-peer networking

One of the first choices you have to make when building a multiplayer game is choosing between building for peer-to-peer or authoritative networking.


What are they?

🤖 Authoritative

Authoritative multiplayer servers are responsible for managing game state and telling players about updates to the game.

Notable authoritative games:

  • Fortnite
  • Roblox
  • Rocket League
  • Among Us
  • Valorant
  • Minecraft
  • Overwatch
  • League of Legends
  • Apex Legends
  • PUBG
  • Rust

👯 Peer-to-peer

Peer-to-peer multiplayer consists of one player running a server on their local machine and all other players connecting to their machine.

Notable peer-to-peer games:

  • Super Smash Bros
  • Call of Duty
  • GTA V & RDR 2
  • Destiny

TL;DR

🤖 Authoritative

  • Large lobbies
  • Hack/cheat prevention
  • Latency
  • Reliability
  • Mobile-friendly
  • Web-friendly
  • Firewalls & NAT
  • Anti-DoS
  • Privacy

👯 Peer-to-peer

  • Cost
  • Maintaining legacy games

🤔 Toss-up

  • Complexity

Comparison

Large lobbies (e.g. battle royale & MMO)

Winner: 🤖 Authoritative

Peer-to-peer lobbies frequently don't run well with more than 16 players in a lobby.

The most prominent examples of MMO games ran with P2P are Rockstar's GTA V & RDR 2. They support a maximum of 32 players in the open-world lobby. However, the game is designed such that players are spread out among the world. It's uncommon for more than 8 players to be in the same place. Similarly, GTA V lobbies for games like racing where players are near each other are capped at 16 players.

Authoritative game servers handle large numbers of concurrent players much better because:

  • The server's network connection can handle more concurrent sockets
  • The server can run on higher-end hardware than the players' computers
  • The server can focus all of its resources on just managing the game state (not rendering, input, etc.)
  • World & player state is only sent to other players who can see the player, which reduces network throughput
  • Players have to do less computation locally to manage the game state, which enables larger worlds

Cost

Winner: 👯 Peer-to-peer

Peer-to-peer multiplayer removes the need for paying to run a dedicated server for players since one player is always responsible for acting as the "server."

However, saving money here limits the reach of your game and leads to a worse gaming experience compared to authoritative networking. Make sure that you are willing to sacrifice your game's experience when choosing to optimize for cost.

Hack/cheat prevention

Winner: 🤖 Authoritative

Peer-to-peer games are often structured such that (a) players are trusted to modify their game state or (b) a single host is responsible for the entire game state.

The first option makes hacking incredibly easy since players can run a modified version of the game and ruin the experience for everyone.

The second option reduces the chances of a single player ruining the match, but the host still can hack the game however they like.

Authoritative networking prevents players from hacking by maintaining the game state on a machine that nobody else can control.

If your game has an in-game economy that is affected by gameplay, do not use peer-to-peer networking.

Some of the peer-to-peer games listed above (e.g. GTA V, Call of Duty) are notorious for the number of hackers in game.

Latency

Winner: 🤖 Authoritative (usually)

Playing games on the same LAN

Peer-to-peer shines here when players are on the same LAN. If two players are playing on the same network, peer-to-peer networking removes the need for connecting to a server in a remote data center.

Unreliable hosts

Peer-to-peer networking requires one player to be the host (i.e. act as the server). This means that the experience of the game depends on the quality of the host's internet connection. If they have a poor internet connection, then everyone has a poor experience.

ISP peering agreements

There's a common misconception that peer-to-peer networking leads to lower latency because players can be closer to each other than to the server.

In practice, this is rarely true. Internet service providers (ISP) have peering agreements with each other to exchange internet traffic. These agreements limit the amount of bandwidth that can be exchanged between each other before throttling connections. That means that during peak hours, that bandwidth gets saturated and connections between ISPs suffer.

In practice, players are often throttled by these peering agreements resulting in a terrible gameplay experience -- even though they may be geographically very close together.

Worst yet -- some ISPs don't have peering agreements with each other. That means that if player 1 is on ISP A and player 2 is on ISP B, traffic may need to be routed to a tier 1 exchange point which is usually not close to the player. For example, traffic from players 1 to 2 may be routed from Phoenix -> Los Angelos -> Phoenix just because they're using different ISPs.

How does authoritative networking mitigate ISP peering agreements?

Cloud providers care about making sure their data centers have the fastest connections. This means they work with ISPs to make sure that traffic is delivered to their data centers optimally. Compared to ISPs who work against each other with consumer-hostile peering agreements, this almost always leads to a better networking experience.

Long-distance routing

When playing with players far away, your traffic needs to be routed through numerous exchange points, any of which could decide to throttle your traffic or may be overloaded.

How does authoritative networking mitigate long-distance routing?

Without special care, authoritative networking does not mitigate this issue. However, it is possible to route traffic to your authoritative server through "internet highways" by working with providers that specialize in routing traffic efficiently. This is a topic that justifies a much longer explanation.

Reliability

Winner: 🤖 Authoritative

Peer-to-peer networking requires one player to be the host (i.e. act as the server). This means that if the host spontaneously goes offline, the entire lobby is at jeopardy. If you don't want to lose the game state, your game is expected to be able to gracefully transfer the host to another player.

Mobile-friendly

Winner: 🤖 Authoritative

Mobile gaming is almost always a terrible experience for peer-to-peer games.

Spotty connections

Unlike desktops and consoles, mobile devices are often on a spotty internet connection. For example, a phone could be on a slow cellular connection, changing cell towers while in transit, or far from a wifi router.

This means that mobile peer-to-peer games frequently experience high latency from spotty connections and frequent disconnects mean lobby hosts need to be migrated frequently.

Leaving mid-match

Mobile gamers are more likely to close their game mid-match than players on desktop or console. For example, mobile gamers often play while waiting for appointments or for taking a quick break.

This means that having one player host the lobby often leads to interruptions in the match.

For more details, refer to the reliability and latency sections.

Web-friendly

Winner: 🤖 Authoritative

Limited hardware resources

Web browsers are almost always resource constrained when running a game which means their games are frequently not running with reasonable performance. Making one player the host will mean all players in the lobby have a poor experience.

Leaving mid-match

Similar to mobile games, web games are frequently left mid-match. Making one device host the game for everyone else leads to poor experiences.

Complexity

Winner: 🤔 Toss-up

One of the biggest draws of peer-to-peer networking is to reduce complexity.

Unified codebase & writing your own server

A big advantage of peer-to-peer games is that you can build your entire game with a single codebase and never leave your game engine (if you use one).

However, many developers believe they have to write their multiplayer server from scratch. However, Unity, Unreal Engine, and Godot all have multiplayer solutions built into the engine that supports authoritative multiplayer out of the box. These libraries take care of the complexities of networking and state management for you and let you develop your entire game within your engine of choice.

Managing servers

Another big advantage of peer-to-peer games is that many developers believe you don't need to run any servers.

In reality, you need a bare minimum a signaling or matchmaking server so players can discover and connect with each other. In addition to that, you likely also need to run a relay/TURN either to prevent IP leakage or prevent your game from being blocked by firewalls.

With peer-to-peer games, you don't have to run your servers.

Building authoritative game servers can seem daunting, but peer-to-peer games need a lot of extra work to make sure they run well.

Managing peer-to-peer edge cases

Building a quality peer-to-peer game means you have to worry about a lot more edge cases like dealing with hosts disconnecting, host latency issues, signaling servers, and cheat mitigation without a trusted game state.

Firewalls & NAT

Winner: 🤖 Authoritative

Peer-to-peer multiplayer games require players at arbitrary public IPs to connect to an arbitrary port on each others' machines. It's very common for firewalls to flag this traffic as malicious and prevent players from playing.

Hole punching can be used to work around firewalls, but it doesn't work 100% of the time.

Authoritative servers can be set up to run on well-known ports with trusted IPs to reduce the number of firewalls that block connections to your game. Firewalls rarely block traffic to popular cloud providers.

However, firewalls are often configured to prevent players (e.g. students or employees) from playing games on their networks. Proxy servers can be set up for authoritative game servers that players can connect to if the primary server IP is blocked.

Anti-DoS

Winner: 🤖 Authoritative

Peer-to-peer games often suffer from denial-of-service attacks targeted at the host of a lobby. There's no way around this since the host is required to expose their public IP to all other players, which creates an accessible surface area for anyone to ruin the match.

While authoritative game servers are frequently targeted by DoS attacks also, there are a lot of actions that can be taken to mitigate the effects of these attacks.

Privacy

Winner: 🤖 Authoritative

Peer-to-peer networking requires that players connect directly to the host's machine. This means that players are exposing their public IPs to either the host or even the entire lobby (this may be required if implementing host migration).

Public IPs can be used to obtain a rough location of where a player lives and expose players to potentially targeted DoS attacks. Players do not like having games expose their public IP, so they often play games using a VPN to mask their identity, which leads to higher latency.

This can be mitigated by using relay/TURN servers, but now your game is responsible for running more authoritative servers and loses many of the advantages of building a peer-to-peer game in the first place.

Authoritative servers do not expose players' IPs to each other. Players connect directly to the server, so the server is the only machine that knows the player's real IP.

Maintaining legacy games

Winner: 👯 Peer-to-peer

Games are famously built on a Hollywood model that requires new games to be launched every couple years. This means that studios often have a growing portfolio of legacy games that are tough to maintain -- especially since each game often has significantly different architectures.

Peer-to-peer networking is attractive since there are less servers to maintain.