Monorepos: The answer to multiplayer online game development challenges
Developing a project such as an online multiplayer game is not an easy task, it requires a lot of technical knowledge and a lot of patience. Every videogame developer agrees on one thing, creating an online multiplayer game can even triple the development time, if it is not abandoned.
That is why it is very important how the project is developed, to have a firm foundation to build on and make sure it is stable and does not collapse in the middle of development. In this article I will talk about how we at Lick & Load have followed an optimal and scalable way of working that has "facilitated" the development of our online multiplayer game.
What is a Monorepo?
Simply explained, a monorepo is a repository where the different applications or packages that make up the project are located. In this single repository the constituent parts may or may not reuse code and / or dependencies, in addition to being able to create multiple tasks between the different parts of the project, such as running all applications at the same time, which can save time and facilitate development.
This type of technique is not something new or something that few people do, in fact, companies like Google and Facebook have been developing in Monorepos for many years, this is something that brings confidence and value.
How does a Monorepo help in the development of a multiplayer game?
When making an online multiplayer game it is important to think from the beginning about how people can try to annoy the other players by cheating the system or making use of hacks that make their game much easier. That is why the use of techniques such as 'Authoritative Server' are very common and important to improve the user experience.
This type of games with 'Authoritative Server' (we will explain in future articles its benefits and go in depth about this topic) usually have code that can be in many cases the same for both client and server side, so making good use of code reuse can be crucial in these cases. Thanks to the monorepo this code reuse, or in some cases, of dependencies or packages, is done in an effective and simple way thanks to the tools they offer us.
For example, if the UI of both your game and your promotional website is practically the same, with the same colors and components, you could create a UI package that both applications share and therefore any change made will be reflected in both applications, something that in the long run saves a significant amount of time and makes the project more scalable and maintainable.
If we talk about the use of monorepos in the case I mentioned about an online multiplayer game with authoritative server we could use this technique to reuse systems that share both client and server, systems like physics, character movement, etc.
The good and bad of using Monorepos.
The technique of using a single repository that encompasses the parts of a project is not always the best idea or the best way to develop, as always in the world of software development we must analyze each project separately looking at their needs individually. There is no best or worst technique, there are simply right and wrong ways to develop the idea.
Advantages
- Better collaboration: By having all the code in one place, developers can easily see and understand how the different parts of the project fit together. This facilitates collaboration and communication between team members.
- Greater code reuse: Developers are more likely to reuse existing code if it is readily available in one place. This can save time and effort, and can also help ensure that code is consistent and of high quality.
- Simplified dependencies: By managing all dependencies in one place, project installation and configuration can be simplified. This can be especially beneficial for large and complex projects.
- Ease of maintenance: It can be easier to maintain a project with a single repository, since you don't have to worry about synchronizing multiple repositories.
- Better visibility: A monorepository provides a complete overview of all project code, which can be useful for decision making and strategic planning.
Disadvantages
- Greater complexity: Monorepositories can be more complex to manage than multi-repository repositories, especially for large projects with many teams.
- Steeper learning curve: Developers may need more time to learn how to use a monorepository effectively.
- Risk of increasing repository size: As the project grows, the monolithic repository may also grow, which can make it difficult to clone and use.
- Potential performance issues: A large, monolithic repository may be slower to clone and query than several smaller repositories.
- Security concerns: Sharing all project code in one place can increase the risk of security problems.
Carried over to our Lick & Load game.
In our case for our multiplayer online .io shooter game we have carried out a monorepo with the following applications and packages:
- Apps:
- Game
- Web/Blog (this site)
- Server
- API
- Packages:
- UI
- ECS (design pattern that we will discuss in future articles)
- ...configs (Typescript, Tailwindcss, etc)
As a tool to create the monorepo we have used Turborepo, it offers us the creation of monorepos in an optimized and simple way.
Conclusions
I hope you have understood the concept of Monorepo and how it can be used to simplify the development of an online game or any other similar project. You should analyze your project and determine which technique is best suited to your needs.
Thank you very much for reading, I hope you got some information for your game or at least you got something good, I wish you the best and I hope you can develop the next Agar.io. Best regards :D.