How to Choose Your Multiplayer Backend

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
if you're just getting started with your multiplayer functionality or maybe you're unsure about how to implement that backend or what that technology stack is going to look like well I'm going to review five common scenarios based on game type to help you pick the best multiplayer [Music] strategy so the first thing I want to say is that this isn't necessarily AAA production ready advice this is for beginners small or medium-sized Studios that are really unsure about which technology stack they should be using so let's start with what is a server and why do we even need it well I like to imagine a server is like playing a soccer game or football game depending on where you are in the world and it's a way and it's a means to connect everybody together right so to play a soccer game you need everybody on the field that's kind of what a server does for us it acts like a field that we can all come together and connect to and play the match that we're trying to do whatever competitive game that we're trying to do it's a means for that I think that there's another component where the server acts kind of like a referee and it determines like how long the match is going to be there's time limits right so there's a start time and an end time there is a minimum amount of players that can that can join the game and play and be on the field at any given time and he determines when the fouls occur and when someone was off sides or when a goal was scored and all that is important to capture when playing a game we need a way to save and get data and make sure everybody's on the same page to inform whoever is playing the match that these are the things that are actually happening this is how many goals have been scored this is how many players are in the match this is who's in the match and that sort of thing and and this is where we are so the server like a soccer match is a place where we can get together and play the game and it also acts as our referee to make sure that the rules are being followed that the game is being played so if I score a goal but maybe my client was a little slow and the calculations weren't correct on my client cuz I had lag or a slow computer that server entity that referee can actually make the final call just like in a real game whether or not that was a goal and whether or not that goal was scored and and and you can extend that analogy like was I out of bounds was this actually a foul and and you can use the server as like what we call an authoritative server to be the sole source of Truth to let the players and the people in the match know what's actually happening and what the final call and a lot of these things are in the game and there are hybrids of this right you can have a client authoritative heavy game where maybe you let your player say yeah I scored that goal or no I wasn't off sides and you can report that from your client to the server so that the server just listens and takes your word for it right so you don't have to do that but I get a lot of developers coming into the Discord and I ask some about server authoritative and what their plans are with that and a lot of them say yeah I'm not really doing that I'm just starting out I just want to get this game out there and that's totally acceptable a if you're just starting out you don't really need to stress too much about having everything on your server be the golden copy you can allow your clients to report some of those actions as an authority but just keep that in mind when as your game grows and you're getting more and more people you're going to expose yourself a little bit more to exploits or cheating and once the players can start breaking rules then you know it doesn't become fun to play anymore so just keep that at mind if you go that hybrid route or if you are a full client Authority that there may be some issues longterm with your game so it allows the game to be played fair and it cuts down on cheating and it just makes sure that everybody's following the rules so when you're building out your game and you're thinking about which technology stack to use you need to keep in mind two things how much of the client gameplay do I need to simulate on the server to make sure that everything is happening correctly and how much is this going to cost so the first option I want to look at is where you are building your project in let's say Unity or gdau and you've got your client and server in the same project and you need to create a dedicated server build and that you'll deploy that server somewhere right so I'm going to call that client game engine and server game engine right and you're always going to build this and keep this in the same project like you're not going to have two different projects and if you're coming from a like web development backend that might seem a little foreign to you but with game development the way that these apis and and these underlying networking packages work is they're all kind of contained and it just makes sense to keep them together because of the way that they communicate with each other through like rpcs and syn bars and that sort of thing it it it needs the paths to be exact now you can separate them out and it's bit it's a bit of a headache I've tried it before and you can do maybe like a common library to you know make sure that those networking paths remain the same but it's a little bit more trouble especially for these small or medium Studios or for beginners so maybe some AAA Studios might do something like that but ultimately if you're just getting started I wouldn't worry about that so you've got your game project with your client code and your server code in there and you need to create a server build so you go up there and you create a dedicated server build and you deploy that to some server so this is what most of us are going to use right so we're not going to create some other service or something like that to act as our backend we're actually going to use a gdau server or a Unity backend server to act as our backend uh relay there right so you're ultimately just connecting with all these Technologies to some IP and some Port so when your client joins the game maybe you some matchmaking it's going to connect to this server and these Network Technologies that these game engines provide out of the box are really nice they have very feature-rich functionalities like rpcs which are remote procedure calls sync variables Network transforms they can do spawning or seam management all sorts of functionality that these major engines provide out of the box and there are dozens of thirdparty networking libraries that if you're just not happy with what's built in you can probably go especially with Union you can go just download some other package like Photon or whatever and put that in your project and you'll create a build and the network just connects behind the scenes for you you just provide whatever the IP is based on your matchmaking results and you're good to go and this is what most of us are going to use we're going to have that backend Unity server that's built as part of our main project and we're going to Leverage The built-in networking functionality net code is the big Unity One now they just released I think the first version earlier this year or late last year I've done a couple videos on that so go check those out but it's a really good uh Network abstraction and it works really well and with this setup this is where you're going to have the most true simulation of your client gameplay right so your clients are playing that data is synced to that backend server and a lot of times we don't even have control over the actual player we just have control over the input like a do has examples that show this where your only Authority as a client is the buttons you press and the mouse movement and that gets synced to the server and then the server comes down and then moves your player and then tells the other clients what you did based off what was transmitted as your keyboard inputs to the other clients right so it's a it's a little difficult to understand and I'm sure there's some efficiencies that they've added to make that easier and maybe it might not be exactly how I described it but ultimately you want to have your client with the least amount of authority as possible so that your server Remains the sole source of truth and another thing to note is some of these game engine packages like with net code you do get a out of the-box interpolation algorithm or prediction algorithms uh that allow the synchronizing of your clients to be done in a really easy manner your client is moving you're controlling the game and he's moving pretty quickly somewhere well your data transmission is probably a lot slower than how fast your inputs are that your uh frame rate is calculating your player's movements so it's a little slower than that so what they have to do is interpolate where their last data point that they got of your position was to where you were going to go and then they they smooth that out for you and otherwise it would be really jittery so by using some of these built-in Technologies you get some of that handling and some of that smoothness handled for you and using the built-in networking uh libraries is probably the easiest method to go when you have access to rpcs or network transforms and and any other kind of synchronizing apis that they give you it's going to be the the easiest to get up and running you're not going to have to sending Json and building these messages and custom messages and managing and and checking on oh which op code did I get and that sort of thing this is really the default this is what we all kind of start with and we all think that we need to use it but it's not necessarily true and I'll touch on that in a minute but the game types that are best suited for this are fast-paced data heavy games where you need to simulate on the server what's happening on the clients you need to make sure that wherever those bullets are getting fired that the ray tracing calculations are being ran on the authority server and that we have that source of truth that gets transmitted throughout the other clients to make sure that the game is being played fair so you're thinking you know heavy open World Games first-person shooters you know Halo Call of Duty maybe fortnite High action adventure games where there's a lot of world that you need to make sure that where the player thinks they are on the client that's where the server knows they are and and if there's any kind of disconnect the server will correct that and and it'll sync that data back and forth to make sure that those players are where they should be and any kind of heavy environmental interaction that needs to be simulated if you have objects that they need to stay within or paths or maybe world map bounds like anything like that you're going to want to use this this full-blown uh backend of your game engine uh whether it's gdau or Unity or unreal you're going to want to deploy that backend server so that you have access to what the clients are playing and so that you can simulate those physics calculations like if you hit something a certain way on your client it might look different from where the server has you at on the map right so if there's two players and there's a little bit of lag involved and are coming at each other your server might have a little bit different position about where they actually are and it's going to calculate that physical interaction and it's going to send the results of that interaction to your other clients who are involved in that game and that'll be the ultimate source of Truth and ultimately what is considered what actually happened in your game so that's really what we what we mean when we say authoritative server and this route is going to get you the the best way to do that so you're probably wondering well where do I deploy my dedicated server build well there's plenty of options available for you now if you're using Unity the first thing you can do or check out is their game hosting service so they have a build to deploy pipeline where you have some fleets and you can scale your game there and it's very nice I've did a video on that so if you're interested go check it out and they have some matchmaking functionality it's really good uh if you're interested just to stay within the unity ecosystem which I kind of recommend you know go check it out now if you don't want to use unity's backend service for whatever reason check out AWS I use AWS for a lot of work and I like what their uh game product is called gamelift so they offer a whole Suite of functionality you can scale your Fleet there's a very nice build to deployment pipeline uh there's fleets where you can scale and grow as your game grows and they also provide some matchmaking functionality now if you're looking to just spin up something very quickly you can also build your dedicated server and deploy it on an ec2 instance and maybe there's probably a dozen other services on the internet like red hat or Microsoft I'm sure has some version of it and there's probably a bunch of thirdparty uh services that are specific for deploying a game backend I'm not too familiar with them I don't really use them but I'm sure they're out there like I think Photon actually has their own service so if you're if you're using photons networking you you know you can go check them out too but one thing I want to clarify is I've seen this brought up a couple times and this is a misconception where you're building your game client right so what everybody's actually playing for Windows well I need to deploy my server as Windows as well that is not true you can deploy your client for Windows but your server can be deployed as Linux and I actually recommend this because I've never seen a cheaper Windows Server over Linux ever so Linux has always been cheaper at least in my experience so deploy your dedicated servers as a Linux server build and there's a lot more support out there it's where the industry leans Linux is very industry is kind of an industry standard overall I think it's easier to use and you don't get this clunky Windows Server stuff I don't know I'm maybe I'm biased but it's definitely going to be cheaper to use a Linux server build so don't think you're limited to Windows only servers you can definitely deploy your gdau or your Unity backend as a Linux dedicated server and I have videos on how to do both of those so if you're interested go check those out so the next technology stack we're going to talk about is using websockets websockets is like an active connection uh built on top of TCP where your game client will have an active connection to some backend server and it doesn't have to be a dedicated server build like in the previous section this can be some other Standalone server it can be serverless so there's a few different options here right so you can use a dedicated server build and spin up a websocket uh server on on that build and then still connect to the client but I don't know why you would do that there's much cheaper routes maybe if you had to do some one-off simulation I don't even know what that use case would look like but if it were me I would just use a Lambda serverless websocket uh setup on AWS and my game client would just start up and connect to that websocket through some matchmaking that you could also do with Lambda and it would provide you that IP and you would just establish that connection with the websocket I generally use AWS Lambda because it's very easy to spin up a websocket server there and because it's serverless you're only charged for how long your players are connected to it so if you have a multiplayer card game let's say and you have five people in a match well you're going to connect five people to that websocket and it'll turn on when those initial connections up and then it'll shut down when when everybody when the game is over so it's really great for handling those like slower paced transactional style games like card games or turn-based games uh you can do real-time strategy games that are really slow like if you don't need to track movement where it's super fast and you just need a little bit of movement tracking this is a great a websocket is an active connection so it's a great way to track those types of slower Pac games and a lot of times people come into my Discord Channel and they're they're like I need to put this dedicated server build the first thing I always challenge them with is why do you need a dedicated server build it's going to be much more expensive than some other solution like a websocket and I make them tell me their requirements and if it doesn't look like they need it I always try to direct them back towards using a a websocket and a lot of times people don't want to do that because it's scary it's a new technology it's foreign to them they're they're already familiar with gdau or unities built-in Network abstraction layers and all those things and that's totally fine go with what you're comfortable with but just keep in mind that wherever you're hosting that dedicated server build it's going to be much more expensive than using something like a serverless Lambda function uh connected through some websocket so if you can get away with a websocket for your game I would definitely recommend it and websockets are widely supported you can build it with any technology Java node PHP whatever you're familiar with wherever you want to deploy it maybe you're not even making a game maybe you have some other use case and you already have some server somewhere and you just need to connect a Unity client to it definitely check check out websockets it's very easy to use now one of the drawbacks about websockets is you you don't get those like built-in Network transform rpcs and sync variable things you're you're actually going to have to manually build messages and send those messages across the wire and I do have a couple videos of that uh using unity and some other demonstrations that I do but if you get with your team and you come up with some kind of standard for what your messages are going to look like and you have some kind of parent object and you flesh all that stuff out it'll actually be pretty nice to use all right well the third thing we're going to talk about is custom networking this is where you get access to some underlying Network transport layer like UDP or TCP and you build on your own uh or you're bake in your own kind of improvements to that or however you want to handle this networking technology now you don't have to build your own there are other abstractions out there like mere telepathy I think it's kcp and it's some amalgamation of UDP and TCP together and it kind of handles like The Best of Both Worlds now that's just one example there are dozens out there already uh with gdau I think there's a few and with unity I know there's several out there this is where you're going to want full control over the messaging and the the the network pipe and how these messages are sent and like what size packages and and maybe the meta the metadata that's sent and if you want to reduce those things so this is where you want that fine-tune control over your network uh your layer so like I said before there are other packages out there that exist that made improvements to this like I think with gdau what you're actually using is an improvement or at least one of their Network layers is an improvement upon TCP like it's like a TCP but without the extra data overhead so it sends a little bit faster and then maybe UDP they have a version that is a little bit more reliable right because in general TCP is going to be ordered it's going to be reliable and it's going to be a little slower because of that extra you know data and you know communication that needs to happen to make sure things are flowing correctly whereas UDP doesn't really have a connection idea right it's just sending data as fast as possible it doesn't really care if you drop a packet or it doesn't really care if you receive those things in order so it's kind of up to the end clients to figure those things out and a lot of times you'll see these custom Network abstractions that will build on top of these to make it a little bit better maybe the to both worlds so so that you get this really nice Network layer so if you are doing something that needs custom networking you need to get in there and and work at the lower level apis all these game engines provide that I know gdau has it I know Unity has it so definitely check those out if you're interested or maybe you're just interested in doing it because it may be fun to write your own network abstraction layer on top of these lower layer Technologies so definitely check those out if you're interested and again this is something that's much more advanced I don't recommend that beginners look at this this is where okay we we get in here we're doing some research we're a A midsized or larger studio and we need to do some serious customizations like these these Network abstractions are just not working out for us we need to go in and and build and do some customization for these things to to tailor it for our games requirements so again not for beginners but do have that available to you if you want to if you want to check it out and definitely go read about it it is pretty interesting and this can be used for any game um but again it's definitely for probably the more advanced use cases so the fourth option we're going to talk about is peer-to-peer so I would generally say to not do this if you are creating a production ready video game or multiplayer video game because there are serious limitations to how this is going to scale right if you just have a peer that is acting as a host so a client and server and then everybody just connects to that one peer that acts as the authority that's not not going to scale well now if you're going to do this for your friends and family or whatever if you're just doing it for development and testing that's a good idea but to actually do this for a production level game it's not really ideal there's limitations with scaling and there's severe security implications that you know if I'm the authority you have to trust the authority is going to be valid there so I would stick to using peer-to-peer for development and testing and unless you know of course you're not really looking to scale out to a large production roll out and one thing I want to mention though is that peer-to-peer doeses work for dedicated server builds for custom networking or websockets or whatever you want to do you can do it it's great for development and testing but again I don't really recommend it for production level builds another technology is called Web RTC and this is a newer technology it's the one I'm least familiar with but the idea is direct peer-to-peer connection that is very high quality it's a very high fidelity high standard protocol I think that was originally developed by Google and and it's it was mainly used for audio and video transmission but it it really can be used for any arbitrary data transmission now this again is going to need some kind of relay to know who to connect to but then once that network connection can be established the clients will connect to each other directly so I'm not really sure what the use cases for this is I mean I know it was originally developed for browser applications but all these major platforms support it now gdau supports it Unity I think Unity supports it I'll have to double check on that one or maybe somebody can check on me I think I missed that one but in general this is like one of those like one-off scenarios I don't know maybe you have a game and you want to be able to yell at the other person that you're playing so you can connect to some server for your gameplay and then maybe you can use this web RTC to yell at the player and have a like live I don't know video chat with them or something like that or I think I read one use case was if you had a drone and you had an app that was going to communicate with that drone and you wanted to have that direct line of communication back to your your device your Authority device you could establish this connection and send that high quality audio and visual data back to that to that main Authority device so the fifth and final option that I wanted to review is using serverless Technologies to handle those non-critical gameplay functionalities so the ancillary things that you need around your game so things that you don't necessarily want to put as part of your dedicated server build or whatever you're using as your backend but you still need a backend to handle them so that's where AWS Lambda or some other serus technology really comes in handy so these are like those one-off requests where let's say you're making a inapp purchase or you need to connect to steam for some authentication or gameplay related things like oh I got a loot box or I found a new card or maybe you need to develop a chat system you can generate a matchmaking or Lobby system with this uh it's pretty powerful what you can do with these serverless Technologies and you can call to them at any time during your game play so if if you don't want to slow anything down while your game is running your server or your client can make HTTP requests to some Lambda function some serverless function to handle these kind of oneoff ancillary support functionalities that your game may need and some other use cases are like collecting analytics or maybe you have a postprocessor to check whether your player has made an achievement or something like that and you just send some data to it I do have a video on how to use step functions AWS step functions to kick off uh like timed events so for example if you have like a strategy game like boom beach or something you're building some uh resource or some building or you're mining something and it takes time right so it takes anywhere from like an hour or 30 minutes to 24 to 48 hours right so you can send off these uh requests to some serverless Lambda function and that Lambda will go ahead and kick off a step function that can actually trigger call backs when it's complete you can actually send SMS messages or push notifications or update some database row there's a lot you can do with serverless Lambda functions for all these ancillary functionalities that you may have in your game so you know you don't necessarily have to rely on your server or your dedicated server build for this type of stuff H you know you're you're essentially slowing down your gameplay and you might even be costing yourself more money because you're causing your server to do more processing on that server I recommend to take a lot of those functionalities and stick them off into some serverless context so that you're not crowding your game with all these functionalities that aren't necessary so the big takeaway here is whether or not you're going to use a dedicated server or a websocket or some other custom networking technology or peer-to-peer you always need to think about first what do I need to simulate does my server need to simulate what I'm doing in the back end and to what degree and if if it needs to be heavy if you really need to track what's going on and you need that physics simulation then you're going to use those dedicated server builds that are going to take your Unity uh engine or your gdau engine build and you're going to create a dedicated server and you're going to use the networking Technologies to simulate those things to make sure that you're capturing and you're analyzing the data that needs to be done so that your game can function properly so that you can detect cheating so that the rules in the game is played Fair Okay so the other thing is cost right so doing a dedicated server build is going to be the most expensive versus serverless or some websocket connection that only runs temporarily and it's generally because you're always going to need to have at least one server instance running so whether you're using gam lift or unity game hosting Services if if you're going to have an active multiplayer game you might not have people playing the game at all times but you're going to need to have that server there so you have that good user experience of when someone decides to play your game and they finally find a match and they go and play that game if your server's not up and running that's going to be a poor experience for them so because of that I always like to say that it's going to be generally more expensive to have some back-end server versus a serverless version where it's only used when the clients are connected so just keep that in mind and another thing I just want to finish up with is don't let your server builds get too big once you start into your multiplayer development keep tabs on how large your server builds are so go up to gdau go up to Unity and create that dedicated server build and just check on it because if you notice that it's getting larger then you may be doing something wrong because ultimately you should really only have maybe scenes and scripts for your server build you don't need any kind of assets or front-end client assets that need to run on the client because your server builds are going to be headless they're going to be your dedicated server builds are going to be headless meaning they're not going to have a UI they're just going to be running the functionality of of your game they're going to be simulating the back-end game and if you notice that your your dedicated server builds are getting large investigate that early on and make a change in a decision to correct that early on because if you wait too long if you wait where you're like the second year into into development it's going to be much harder to backtrack that because your game is going to be so much more involved and that technical debt is going to be overwhelming to pull out that and correct that action at that time anyways if you enjoyed this video please give it a like and if you want to see more multiplayer content definitely subscribe I've got a lot more in the queue have a good one thanks for watching
Info
Channel: Battery Acid Dev
Views: 11,069
Rating: undefined out of 5
Keywords: godot, unity, multiplayer, game development, server, websocket, p2p, serverless, unity3d, godot engine, dedicated server
Id: sT0UPlJ2cpc
Channel Id: undefined
Length: 27min 55sec (1675 seconds)
Published: Thu Nov 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.