Introduction to In the development and operation of the game, there are many usage scenarios for the database. Faced with the pressure of game access, game server integration scenarios, game rankings and other scenarios, Alibaba Cloud provides users with the best solutions.

This article introduces the best practices in the database game industry from three aspects:

  • Database application and demand analysis in game architecture
  • game Redis/Tair technical level
  • MongoDB game best practices

1. Application and demand analysis of database in game architecture

There are three mainstream game architectures: 1. Division and server. 2. Full service in the whole district. 3. Same service globally.

1.1 Alibaba Cloud Database in gaming servers (partitioned servers)

image001.png

See the picture above to introduce from the top, middle and bottom:

On the road, when a user logs in to obtain a game account, he can obtain partition information and version information of the server. The user account and order are stored in the relational database PolarDB. User partitions are divided into servers and information is cached in the Redis/Tair database. Red is database usage, and yellow is cache usage scenario.

The middle road is the core of the game, GameServer, a strong computational data structure. The experience and equipment in the game will be periodically flashed into the database. The character storage of game data is written into the database with Json semi-structured, and the data can use PolarDB and MongoDB. In GameServer, there are distributed locks, leaderboards, casting records, etc., and Redis services or Alibaba Cloud's Tair will be introduced.

Bottom road is very important, there are many activities in the game, a large number of log records are stored in an analytical database. For example, if you want to see whether the game is effective after a game launch event, you must analyze the report formed by the database. Analytical database is very important for anti-cheating, anti-scalper/anti-scratch, etc. To do data analysis, you need to import different sources, such as logs, roles, accounts, etc. Alibaba Cloud's AnalyticDB is most suitable for this job.

See the upper right corner of the picture, the partitioned server game is a bit to the point and cross-server battles and other interactive information. This message system uses the Lindorm service area to store.

1.2 Alibaba Cloud Database in gaming servers (same server globally)

image002.png

Global Uniserver is an architecture that major game manufacturers have invested heavily in. Because the use of multiple game platforms such as PC, mobile phone, Switch, and PlayStation game consoles for seamless gaming and interaction will improve the user experience to a very good level. There are also such games in China that are sold globally.

The architectural feature of Global Uniserver is to use a centralized database, and the game centers in different areas of the front end will write the data into a unified database in a centralized manner. The core of the global same server technology is the Cache Server in each region. It is the core to improve the gaming experience. It will periodically flush data into the back-end database in batches, and will also update the updated entries in the database to other servers.

1.3 The overall demand for databases in the game industry

image003.png

The gaming industry itself is highly dependent on memory computing and network resources, and then the database. I have visited many game customers, and I remember a CTO of a major game company said to me: "The farthest distance in the game is not the distance between the data and the database, but the distance between China Unicom and China Telecom."

But although the game industry does not require high database performance as a whole, it has very high requirements on the stability, smoothness, and degree of operation and maintenance of the database.

The first is the smoothness of expansion and contraction. Since Ali’s database technology was initially developed around e-commerce, the two industries, e-commerce system and game system, have very different ways of using cache and memory database. For example, e-commerce's demand for database fault tolerance is mostly based on the philosophy of "dead early and overtake life", and do fast fail. If access to the data fails, the data layer needs to fail quickly without getting stuck. In this way, the user can retry quickly, but if we apply this logic to the game service, if the connection to the database library fails once or twice, the connection is broken. The game user may be kicked out of the game directly.

Therefore, we have specifically made connection retention capabilities for scalability and high availability. Not only does the expansion and shrinkage continue to link, even if a high availability event occurs on the Alibaba Cloud cluster version of Redis/Tair, for example, the Tair back-end database is switched, the front-end can still be used. Stay connected constantly. In the event of Tair's expansion and contraction, the jitter on the service side can reach about 100ms, which is almost insensible. Cloud-native databases like PolarDB, which are separated from storage and computing, also have the ability to switch and continuously link with HA. In this way, the smoothness is guaranteed, and it is also a very big improvement for the user's gaming experience.

Another scenario is that although the overall performance requirements of the database are not too harsh in the game industry. However, there are also popular activities such as team battles with 10,000 game users and the launch of new areas. This requires a high level of resistance and smooth scalability of the database as a whole.

The demand for databases of games on the same server globally has gradually moved towards cross-domain multi-activity. The cross-domain multi-activity of modern databases has also become one of the core capabilities of the database, which can greatly simplify the user's use scenario.

1.4 The game industry prefers cloud databases

image004.png

The gaming industry is an industry with a very high iterative speed. In some core service capabilities, such as Alibaba Cloud Tair, its storage structure is closer to customer data and closer to ORM. It provides some packaged distributed locks, distributed rankings, counting services, etc., which can make games Iterate at high speed.

Similarly, game users are one of the industries with the most database operation and maintenance operations. This is related to the business characteristics of the game itself. For example, in some games that are divided into servers, their operation and new model is to open new servers and merge old servers. The game has frequent operation activities, operation and maintenance of a large amount of data relocation, data cleaning, and some partition and server services must be frequently combined, rolled, and version updated, and they must be frequently backed up and filed after being sent. The database itself must be enhanced on the core of the database, and it must also interact with the surrounding ecology. If contemporary databases do not regard operation and maintenance systems and ecosystems as first-class citizens to build, they will gradually be eliminated by the market.

In terms of cost, a pooled database can better configure resources and achieve better resource allocation. In the game industry, two costs are significantly underestimated. One is the operation and maintenance cost, which has a high flexibility to expand and shrink the capacity, which can greatly reduce the cost of the business. For example, Tair can choose the memory engine according to the user's business. , Such as AEP engine and SSD engine. The other is the error cost, which is essentially part of the R&D cost. It has better observability and can also reduce the error cost through efficient and standard ecological tools.

2. The technical level of Redis/Tair in the game

2.1 A big picture of Redis/Tair's current game capabilities and technical water level

image005.png

When faced with problems such as stability, high-speed iteration, and cost, cloud databases have great advantages. In the field of NoSQL databases, both Tair and Mongo support the native structure of Json. In addition, non-relational databases are very friendly to the high-speed iteration of games. For example, Tair can do data recovery at any point in time in operation and maintenance, and Tair has the ability to maintain connection in terms of scalability and disaster tolerance. The database also supports the ability to store and calculate. There are many data modules on Tair, which can facilitate the analysis and calculation of game users.

Tair cloud native memory data is fully compatible with Redis protocol and commands. Redis is one of the indispensable databases in game services. The architecture diagram above has been introduced. It can serve both cache and memory database scenarios.

But on the native community Redis, its exploration and expansion are very uneven. There have been great improvements on Cloud Redis, but it still crashes; on Tair, connection maintenance, high-precision detection and switching can be achieved; if self-operation and maintenance Redis is in backup and recovery, only human operation and maintenance can be done. Cloud Redis can be destroyed without perception and automation through a good infrastructure. Tair can ensure data security and recovery at any point in time. For the AEP/SSD engine, there is also an adjustable version of the synchronization capability on the line, which can better adapt to the data lossless scene.

Cloud databases have better observability. For example, once a large key is encountered in Redis, it is difficult to observe the hot key. The cloud database has greatly improved the observability on the kernel, and has better controllability on Tair. For example, hotspots can be found on Cloud Redis, and on Tair, the acceleration capability can be used to instantly change the value of a single Key. Reading ability improved dozens of times. This capability comes from the hotspot hashing technology in the e-commerce system. It is a simplified version, but it has a more flexible optimization configuration capability for the game scene in the service. There will not be millions of hotspot visits in the game like the national grabbing Maotai in the e-commerce system, and the query cache is enough to enable the game business to better respond to emergencies and flood challenges.

Redis often works on a synchronous link, and if it is slow, it will directly affect the experience. If you encounter it in the game, you need to talk about it first, and then check it and fix it slowly. Again, although the game does not require high database performance, but insurance must be there.

In terms of accelerated development, self-operated Redis can run some enterprise-level modules designed by Redislabs, but these modules cannot be used by cloud vendors. There are a lot of multi-data modules commonly used in the industry on Tair. Some of them are fully compatible with Redislabs modules. For example, the commonly used Json modules in games are fully compatible with reJSON. TairZset is a multi-dimensional ranking. You can also use the SDK provided by us to make a scalable and high-performance distributed ranking. It is also based on TairZset. The online one is TairSearch, which is compatible with Elasticsearch's grammar, and can index and segment the content stored in Tair. This way, combined with the powerful capabilities of the Tair engine, a very good gaming experience can be achieved.

2.2 Scenario: Tair's global livelihood is used in games

image006.png

Here are a few scenarios. The first scenario is that the database is more active. This scene is widely used in all-server games in the region.

For a personal experience, a veteran game manufacturer recently launched a game on the same server globally. It remade a game 20 years ago and changed the divisional server to the global server. The result was very unsuccessful. Until today, when you go to play, you are in line when you log in. It's a pity that I am a hardcore player of this game. Most of my dark circles are caused by work. The recent increase is actually related to this game.

On the forum two days ago, their technical manager wrote a very long article of more than 3000 words, explaining why the problem occurred. I have read it carefully and experienced it several times. In fact, I am explaining the technical challenges of how business data is facing the world. It is necessary to have a good experience, but also to ensure that the data is consistent. If there is no global multi-activity database, even an established game company with very strong technology and planning will also be in trouble.

If I didn't really give up this game because of my feelings, it would be unbearable to drop back the file every day. Using the global multi-live database such as Tair can give users a good experience, which can make the global multi-live game have a very good body feeling.

The picture shows a typical usage of a game client, a shopping mall roaming between Chinese and American game servers.

2.3 Scenario: Data recovery at any point in time (PITR)

image007.png

The second scenario is database recovery at any point in time. This scene was originally a scene to prevent deleting the library and running away. It has a wide range of uses in the game industry, such as game releases, and problems can be quickly rolled back. At the same time, we also dig into the feedback and suggestions of game customers. When restoring at any point in time, we can selectively restore part of the Key/Key Pattern, or selectively discard certain types of Key/Key Pattern. This Key-level PITR is specially developed for the game industry. The database products can be more attached to the business scenarios of the game to do some capabilities, so the happiness of the business is still very high, and the chance of making mistakes is also reduced.

2.4 Data structure modules (modules) supported by Tair (Redis Enterprise Edition)

image008.png

As an enterprise-level Redis, Tair's typical feature is that it supports a large number of extension modules, including simple and easy-to-use data structures that can improve happiness, as well as some industry-level overall solutions. In this sharing, I will only briefly talk about the circled ones, which are often encountered in game development.

2.5 Scenario: High-performance distributed lock (CAS/CAD)

image009.png

All Internet applications need distributed locks to deal with resource competition. In the Redis scenario, we found that there are many practical cases of distributed locks in the industry, but many of them have problems in implementation. The main technical point is that the distributed lock is not deleted correctly, which may cause the resource competition on the business side to fail. We have built a distributed lock in the Tair engine, and only need to set it up to reduce the cost of making mistakes. Distributed locks are used a lot in the Alibaba Group, games and the Internet industry. This Tairstring module is open source and has no restrictions. Users can use Redis to plug it in, and they can get better benefits.

2.6 Scenario: Multi-level sorting and distributed leaderboard

image010.png

Redis's ranking is a problem that cannot be avoided by all games. The problem with the ranking is that it is difficult to expand in parallel with the big key. The ranking in the game will be deliberately designed to be deeper, which is particularly difficult to click. Redis's ranking is the most The pain is that it is easy to form a large key and can only sort one-dimensional data, and the additional data carried is limited.

We have also built a module for multi-dimensional sorting in the game, and made distributed rankings through the expansion of the module. The service capacity is expanded in a balanced way through the number of shards and the overall increase in resources, so as to solve the problem of large queries for game users.

Similarly, the TairZset module has also been open source. Combined with the distributed leaderboard in Tair's SDK, users can easily apply the scalable high-performance leaderboard infrastructure. There is no need to maintain a dedicated leaderboard team. After all, some small and medium-sized game companies do not have the energy to invest in a professional leaderboard team.

From the above introduction, we can see that the database kernel can help deposit some capabilities into the engine, so it can greatly simplify the development of the business, which is very important for the high-speed iteration of the game industry. In 2017, there was a vigorous Multi-Model movement in the database industry, that is, multi-model databases. In the context of multi-mode capabilities, the database is deeply cultivating the industry, and these capabilities provided by Tair are the real needs of many customers on Alibaba Cloud, and they are also the most used data structures in Alibaba's internal systems.

2.7 Peripheral facilities of game cloud database (DTS/DAS)

image011.png

Regarding the game's integration and rollover operations, the past was very primitive. Either do the backup, cleaning, and merge yourself, or write a long SQL yourself to make data changes. These tools and methods are either in accordance with the agreement, or are passed down by word of mouth from ancestral scripts. Some original cloud services have to submit a service order or something. In the contemporary database ecology, data subscription (CDC) and conversion clarity (ETL) are already part of the database ecology. It is supported by standard full and incremental subscriptions, visual filtering, mapping and other operators.

Ali's DTS fully supports Tair's Binlog protocol. The cost of data rolling and operation and maintenance will be very low and controllable. Ecological tools are still the moat of many databases, and they are also the first-class citizens to build.

Observability is important for high-speed database services like Redis or Tair. The appearance of a big key in the game may be fleeting. Our DAS platform provides a very good observable service to see the real-time scene. The dynamic bandwidth of DAS's observable, controllable, and audit-optimized software can help users reduce operation and maintenance operations.

Three, MongoDB game best practices

3.1 Use MongoDB to deal with common pain points of game databases

image012.png

The MongoDB game framework is natively supported by Mongo, and Mongo natively supports the Json structure, which is suitable for games to store user data.

3.2 Looking at Alibaba Cloud MongoDB from the perspective of development, operation and maintenance

image013.png

MongoDB is suitable for structured storage of games. Regardless of whether it is a partitioned server scenario or a global server, the specifications can be configured by yourself. After MongoDB is on the cloud of Alibaba Cloud, it will be more capable in combination with cloud-based facilities, and it will be able to perform snapshot backups and restore cloud-based facilities to achieve second-level snapshots. The expansion and contraction capabilities are flexible, and the scale, up and down of cloud facilities are very smooth. At the same time, MongoDB has many end-to-end security solutions, which are more standardized and convenient, and can also be used as a good anti-cheating and anti-robot scenario.

The above is a brief summary of the use of Alibaba Cloud database in the game industry, thank you!

Copyright Statement: content of this article is contributed spontaneously by Alibaba Cloud real-name registered users. The copyright belongs to the original author. The Alibaba Cloud Developer Community does not own its copyright and does not assume corresponding legal responsibilities. For specific rules, please refer to the "Alibaba Cloud Developer Community User Service Agreement" and the "Alibaba Cloud Developer Community Intellectual Property Protection Guidelines". If you find suspected plagiarism in this community, fill in the infringement complaint form to report it. Once verified, the community will immediately delete the suspected infringing content.

阿里云开发者
3.2k 声望6.3k 粉丝

阿里巴巴官方技术号,关于阿里巴巴经济体的技术创新、实战经验、技术人的成长心得均呈现于此。