We’ve already mentioned that we decided to go with hybrid architecture for our project for a number of reasons. First of all, in a game, everything has to happen fast — it’s not likely that users will be satisfied if they have to wait for 5–10 minutes to see the results of a battle. Second, all actions need to be free whenever possible — paying for every move will destroy the game economy and thus, the project itself. It’s clear that when we are talking about a collectible game (not a game even, an interface with the most simple of logic), there aren’t that many actions that involve the blockchain, and any commission paid for such action is overshadowed by the relatively expensive collectible assets. Ether Kingdoms has a different situation — there are many actions and events that cannot be all ran through the blockchain. At least when we started the project, there was no suitable solution available.
So we decided to use the following structure.
All user requests are passed on to Frontend, first going through the Firewall to block any unused ports, and leaving only ports 80 and 443 for HTTP and HTTPS protocols. Frontend is written on Node.js and is responsible for game process visualization. It communicates with the backend and statistical systems. The client server, or the user’s browser, is responsible for MetaMask login — user identification happens through the user e-wallet number. This is convenient since it doesn’t require any special registration and login. Then the signature received is passed on to Backend through Frontend.
The Backend that is described in GoLang is responsible for the new game logic. It calculates all of the battles statistics, IMP mining, etc. Also, Backend coordinates with the Ethereum blockchain through a special Parity Node, which is necessary to deposit and withdraw IMP. I’d like to remind you that after players deposit IMP to their game balance — or, in reality, transfer the token from their personal account to our smart contract — all further operations with that IMP balance are conducted inside the server logic, making them quick and safe. When a user wants to withdraw IMP from the game, a reverse operation takes place — the necessary number of IMP is transferred from our smart contract to the player’s wallet. Only these two operations (deposit and withdrawal of IMP) have an Ethereum network transaction fee.
The statics system, as is obvious from the name, is responsible for the visualization of the statistics collected by the Backend module. Most of this statistics can be seen in the game — the information is updated every five minutes. Additionally, this module holds within it the administrative tools: for example, the start of game specials, new artifact and lootbox announcements, etc. This is where the connection with the Backend comes in — this module sends commands like “start a game special from this date, to that date, with these parameters”. The statistics/admin module is written on PHP, using yii2 framework.