Author: Fengchao Technical Team

With the rapid growth of Fengchao business system, the data volume of its core system has long exceeded 100 million levels, and the annual increment is still developing rapidly. The core of the whole system as the amount of data pressure increase, not only system architecture complexity increase sharply, the data structure is more complex, the traditional single node database, has increasingly cannot meet the needs of abundant nest, when single table number hundreds of millions of Oracle managed to withstand, and MySQL to single table must level when it will be difficult to support, Need to be divided into tables and libraries. To this end, a high – performance distributed database, increasingly become the need.

thinking

After the business volume of Internet companies increases, parallel expansion is the most commonly used, simplest and most real-time means. For example, the load balancing device separates the massive traffic into a small amount of traffic that each machine can bear, and supports the entire service through clusters. So when the database can not support when split.

However, stateful data is different from stateless data. When the data is split, data partitioning will occur, and the whole system will be carried out under high availability, so the consistency of data becomes a victim, and a large number of verification tools run between systems to ensure the final consistency. In business, business students may often encounter points library students said, this demand can not be done, that demand can not be done, if there is SQL experience business students may have a question is not a SQL thing, in fact, this is the sequela of sub-database sub-table.

To do this, we need a database to help us solve the above problems. Its features should be:

  • Strong data consistency: Full ACID is supported

  • Table and library: no matter how much data we just insert do not need to care about when to expand, there will be bottlenecks

  • High availability of data: When a small part of the disk of a database or other hang up, our business can not feel, even a disaster occurred in a city room can continue to provide services, data is not lost

  • Complex SQL functionality: Basically single library SQL can run on this database without modification or minor modification

  • High performance: while meeting high QPS, low delay is guaranteed

The selection

According to the above expectations, we analyzed the existing NewSQL distributed database on the market, and the list is as follows:

After considering the open source protocol, maturity, controllability, performance, service support and other comprehensive factors, we choose TiDB. Its main advantages are as follows:

  • Highly compatible with MySQL

    In most cases, it is easy to migrate from MySQL to TiDB without changing the code, and the MySQL cluster can be migrated in real time with TiDB tools.

  • Horizontal elastic extension

    By simply adding new nodes, TiDB can be horizontally expanded to handle and store as needed, easily coping with high concurrency and massive data scenarios.

  • Distributed transaction

    TiDB supports 100% standard ACID transactions.

  • Financial grade high availability

    Compared to traditional m-S replication solutions, the Raft based majority election protocol provides 100% financial data consistency and auto-failover without the loss of most copies.

For the above reasons, we chose TiDB, the distributed database of the core system of The Nest, to replace Oracle and MySQL.

assessment

1. Performance test

TiDB benchmarked with sysBANch, 8 tables with 10 million base data, insert, SELECT, OLTP and DELETE scripts were tested as follows, query QPS reached a staggering 140,000 per second. And insertion is stable at 14,000 per second.

Core server configuration:

Test results:

Through ~

2. Functional testing

Through ~

Access to the

Because it is the core system, for the sake of security, we have adopted a variety of schemes to ensure the reliability of project access and ensure that business will not be affected.

1. Project selection

When looking for the first access project, we made a selection based on the following four characteristics.

In the end, we chose push. Because push service is the core service used by Fengchao to send pickup notifications, it has a very large volume, but the logic is simple and there are alternative external push schemes, so even if there is a problem, it will not affect users.

2. Code modification

** Since TiDB is fully compatible with MySQL syntax, we made very minor changes to the code during the project’s access. **SQL basically zero changes, mainly peripheral code, including:

  • Asynchronous interface modification, data asynchronization into the library

  • Synchronize interface modification to achieve abnormal fusing

  • Stop embedding data migration code

The above three points ensure that the whole system is not strongly dependent on the database, and can protect the database from being overwhelmed by asynchronous library in the case of high concurrency, and the core business can go on normally when the database has problems.

The effect

1. Query ability

After access to TiDB, the dozens of sub-tables originally divided according to the time dimension become a large table. The most obvious change is that under the large amount of data, the data query ability has been significantly improved.

2. Monitoring capability

TiDB has a perfect monitoring platform, which can intuitively see the capacity and node status.

You can also know the load on each node and the latency of SQL execution:

Of course, you can also know the location of the machine, CPU memory and other load:

Network status can also be clearly monitored:

All of this allows the team to analyze problematic SQL, as well as problems with the database itself.

summary

TiDB access process was very smooth on the whole. Due to a lot of access security work done before, it only took 10 minutes to switch traffic to TiDB that day. We also want to thank TiDB for supporting compatibility of MySQL syntax and various useful tools provided by PingCAP. So far, the system has been running stably for more than a month, which well meets the business needs of The Nest.

TiDB renovation completed, feng nest push service to be born and query, most of the news so far, push the service’s largest sunset capacity has reached 50 million, and if push service also now use or MySQL, you need on various depots table plan, many detailed business cannot or difficult to carry out.

The transformation of TiDB is just a small step for Fengchao to explore distributed data technology. In the future, Fengchao will introduce more distributed technology into more business systems to create more extreme products and services.