I have done online games ten years ago, when I first saw the micro-service architecture and found that it is similar to the network game architecture, such as:
First to briefly introduce this online game architecture, some things can not remember, today's online games Daniel see don't throw bricks.
Users download online games client, log online games, the first will perform login services, login service is to assign you a gateway, because the gateway behind the connection is the real game server. After login, enter the game, give instructions, such as you move to a location, the instruction will be sent to the gateway, and then sent to the "mobile system" service by the gateway, mobile system calculation and then through the network Guan Fa to the player client, the player client performs an animation to move you to a location.
If the sub-service communication is also through the gateway forwarding, such as the task system to purchase items, then the task system sent a command message to the gateway, the gateway and then forwarded to the item system and so on. The "Game a server cluster" in the figure, where "game a" stands for the game server you belong to, each game server can carry a limited number of people (at that time the technology a server group up to the same time on the line also thousands of), the number is full, you will log on to another server. "Cluster" represents a cluster of service deployments. The game server on each materializing corresponds to a game service cluster of n servers, but only one user database, the database does not use clustering technology, because you even use the database clustering technology, in the real-time aspect also cannot keep up.
In terms of programming, the following applications are included:
Client. exe
Gateway. exe
Mobile system. exe
chat system. exe
....
Speaking of this, the people who understand the micro-service may have seen, the above gateway is like Nginx reverse proxy server, each game service is like a service in the microservices, if your microservices communication protocol using TCP then the Service section is basically the same. Network game data access is not layered directly into the business processing module, in the game every game execution logic whether it is loading scripts, configuration data or account data are processed in the same logic, not to partition what the database access layer, script access layer, so processing has a great advantage, It is the ability to deal with complex logic without losing efficiency.
In online games, because the inter-service communication is a binary message, it is cumbersome to parse the message and assemble the message at programming time, so a unified class library needs to be designed to make the binary message passing directly into object-oriented invocation. For example, if you call a method, you are actually sending a binary message to the gateway. This is also used in micro-services here, so that the interface to send and receive messages into object-oriented calls, can improve the efficiency of programming development, but also reduce the communication caused by the bug, the interface access layer in the Spore framework has done similar functions.
As for the issue of distributed transactions, in the development of online games is easier to solve (even if there is no customer service), because all things related data in a database, even if not a database is also through the message to synchronize. For example, you cut the monster a knife, your level data rise, physical decline are calculated in a service, if the monster is cut a knife calculation is not in this service, then will send a message to that service, that service calculation monster was cut a knife, if the calculation failed, and then send a message to the previous service to cooperate with this aspect, If the item has been hacked Off, send a message to the item service to calculate, the item service sends back the message and the main computation cooperation. This is actually the most primitive version of transactional collaboration through the messaging mechanism.
and micro-service comparison summed up:
Game (Gate Gateway) equivalent: Micro Service (Nginx or API Gateway)
Game (individual service) equivalent: micro-service (self-service)
Game (Interface access layer) equivalent to: Spore frame (Interface access layer)
In addition, the popular Distributed transaction solution in MicroServices is implemented by means of messages, such as payment, the caller calls the payment interface failure, sends a failure message to the message queue, the payment interface service listens to the message queue and processes the payment failure.
Spore Frame-A simple comparison between the network game architecture and the micro-service architecture