r/howdidtheycodeit • u/Layso • Mar 03 '22
Question How does backend servers spread around world work?
I've worked on a multiplayer game that was only serving to the Europe region, hence a single backend server in the central Europe that everyone was connecting. Not so much players so no need to have multiple servers.
I'm curious about tow things:
- How does backends work globally? Let's say I'm in EU and my friend is in US. Do we connect to the same server? If not, how do we now that we're both online, are all backend servers (let's say one for each continent) communicate like a P2P connection between them? Is there a master backend server that keeps the syncronization between sub-servers? If so where does that master server locates? I do believe GameServers can run on any server according to where the majority of the players in the lobby are connecting from, but if there is another approach I would like to hear that as well.
- How do they handle big login queues like we experience with Lost Ark recently, for example. Do they have multiple servers to login in single region so the load on a single server can decrease? If so how does it decide where to connect?
I'm pretty much into network and multiplayer development so I'm curious what's the way to go with this kind of problems. Thanks in advance
26
Upvotes
8
u/Cotspheer Mar 03 '22 edited Mar 03 '22
Well, your first questions can be broken down into multiple parts. And so are often the system structured. You design multiple backends/servers for different kinds of tasks. For example, the online state could be a "friend"-backend. In general, you don't want a monolithic approach as it introduces a single point of failure. Let's say your "friend"-backend goes down for whatever reason, then within your game, only the friends-list becomes unavailable. Lobbies can also be a separate concern and then when they become full and ready to start the game they get a game server associated.
For the synchronization part, there is no real answer, as there are many technologies that can achieve that. For the "friend"-backend maybe a single database is enough. For the game state, one can use a distributed database like Azure CosmosDB or MongoDB with sharding. Some databases do have a mirror function where they mirror the data state but this is quite difficult as the secondary nodes are often behind and the main node will receive the full write load (DDoS like). Often you organize data region-wise as it is the more common use-case that players play with their friends in the same region.
To the second question. Usually, those kinds of games do consist of one large solution architecture and the different subsystems do get scaled accordingly. So even if you have only one real login server coded, they get scaled with Kubernetes or Docker or some sort of container mechanism. So the system starts to scale out when the load becomes heavy and does redirect the traffic when an instance/server reports that its capacity is maxed. And this can happen region-wise. Additionally, you can utilize network components like load balancers and geo-gateways to redirect traffic to different regions and servers.
7
u/wampey Mar 03 '22
I know path Of exile has servers around the world… your game state starts in whatever server location you first connect to, and will default back to this… however, if you join someone’s instance on another server, potentially in another country, you join that server… I’m sure there is likely some type of central server that controls and replicates authentication and some other things down (writes) that help slow this to happen,
5
u/ISvengali Mar 04 '22 edited Mar 04 '22
Ahh! This has been my day job for 10 years. With FPS networking before that for 5+ years.
All the other answers are great.
Every company tends to do it in similar ways, but sometimes (possibly often) with some pretty big changes.
Typically things are broken up into a set of services. Each service has its own unique challenges. I wont go through them all, just the ones that make sense for the questions.
Services talk to each other. Some folks put a message bus between them, but I prefer handling that in each service.
Auth ::
This is typically the first thing game clients hit. This logs players in. Players are often given a session key. On the back end the servers can query to make sure the session key is valid and often are able to decode the key to get information from it.
Auth is stateless for requests, so often theyre behind a load balancer and can scale horizontally. It does rely on db operations, so that has to be taken into account when deciding whether to use 1 Auth per game or 1 Auth per region.
The player then often select a shard. Which brings us to ...
Edge ::
The edge service is what clients will spend the bulk of their time talking to. Sometimes the edge service is merely a subservice of the gameplay service.
User ::
The user server tracks details about the user. What particular shard they are on. What their state is, ie, logging in, logging out, on shard A, transferring to shard B, etc. If theyre in a Group. This is a very stateful service, though, with any stateful service, you can always push the state into a database. I tend to prefer stateful servers, but there are pros and cons to both.
Typically there is 1 logical User service per region. To horizontally scale them, you can shard them by using a hash into a cluster.
Master ::
This acts like a game specific DNS for game services. Often this can do things like startup instances on machines registered as "I can startup instance of type <>".
Gameplay ::
This is typically whats called the 'server' colloquially.
Backends :
This is a ginormous question. Typically you have different services manage different chunks of the backend. For example, User managing knowledge about the user, with Master managing knowledge about the cluster.
Login Queues :
Depending on game implementation details, either Edge, Auth, User, or even a Queue service will handle login queues. Its almost never Auth because usually it doesnt know about details of the rest of the game. It most likely is User or Edge.