Interviews build rockets, work screw typical.

Many companies (especially small ones) don’t even have access to high-concurrency projects, but they do! Back!!! All!!! The love!!! Exam!

I’ve rounded up a few interview questions for high concurrency/performance tuning:

  • Bytedance back-end: how does Taobao system handle high concurrency customer requests
  • Two aspects of Xiaomi big data development: the difference between ConcurrenthashMap and HashmapD in high concurrency
  • Alibaba Java engineers: how to design double 11 transaction total panel, to achieve high concurrency high availability?
  • Background development side of Shopee: how to ensure that the high concurrency second kill project will not oversold?
  • Baidu test development engineers in three aspects: whether they understand JVM tuning, whether they have done JVM tuning in their own projects
  • Alipay Java engineers three aspects: database performance tuning how to do?

The lack of high concurrent project experience is the Achilles heel of most people. Here I recommend you to contact the project of e-commerce seckill system. The project was explained by Mr. Ouyang Xiu, senior architect of TMD. It took him 9 days to dissect the 15 core technical points of the second kill system one by one, and personally build a system architecture with high concurrent read and write, high performance and high availability.

Now in order to feedback friends, specially open the first section of free audition, you can understand the design process of the second kill system through business explanation.

Here I focus on how to achieve the basic functions of the second kill system, and then I will introduce:

  • Construction of project environment for seckill system
  • How to handle high concurrency on a seckill system
  • Limited inventory, how to prevent oversold?
  • How to ensure system stability and high availability?

First of all, a simple flow chart is used to show the business process of the second Kill system (without involving the technical level), which you can automatically bring into taobao/JINGdong/Pinduoduo’s Double Eleven second kill activities.

Let’s talk about how to implement these features.

How to solve instantaneous large flow and high concurrency?

The e-commerce system will generally set up the one-hour second kill, such as 0 yuan purchase, no threshold coupons, etc. During the Double 11, many people will mock taobao on wechat moments after submitting the order and then transfer it for a long time. After transferring the order, the inventory has been reduced to 0, which is a pain point for users, but also a technical difficulty for programmers.

** Because of the setting of the one-hour seconds kill, once the discount is large, a large number of users will buy up at the same time, the site traffic instantly surge. ** servers, databases, etc., can bear limited QPS, such as the database is generally a single 1000 QPS, once more than the bearing value, the website may crash.

Such as Lu Han and Guan Xiaotong’s official publicity caused the breakdown of weibo, is a typical example.

The core idea of solving instantaneous large flow and high concurrency is hierarchical filtering and divide and conquer. The idea is to filter out invalid requests as much as possible at different levels, leaving valid requests at the end of the funnel.

Specific methods:

1. Static Page Technology

Seckill page is composed of commodity information and front-end page resources. The front and back ends are separated. The page resources will not pass through the back-end server, and the front-end resources will be put into the CDN server. In simple terms, the front-end page resources in another “basket”, not with the second kill server to grab “position”, users get the content nearby, reduce network congestion, improve user access response speed and hit ratio.

2. Cache warm-up

In human language, part of the business logic is written to the cache, without the need to read the database directly, to reduce the pressure on the database server, so that access is faster.

For example, before the activity starts, the product information, purchase limit and inventory quantity set for the second kill will be written into Redis in advance, which is also a way to reduce server pressure.

3. Asynchronous

Asynchronization is mainly achieved through message queues.

Message queues are components based on the Producer/Consumer model used to decouple and Asynchronous operations between two different systems. Producers can deliver (produce) messages to message queues at high speed, and consumers can consume producer-delivered messages at their own pace.

Message queues generally have retry capability. Can continue to deliver until the consumer successful consumption.

Speak English and try again and again until the order is submitted and purchased successfully.

4. [k? : n]

Because of the huge difference in processing power between Redis and MySQL. The actual amount of sink to MySQL is still too much for MySQL to handle. In a flash, a large number of successful buying and order requests are created. The pressure on the order creation service is too great. The mysql database will be operated and cannot process the order creation requests in time, resulting in system failure.

The solution is still asynchronous, using the message middleware to cut the peak load and fill the gap, sending the request to the message queue first, and the order server can consume and create the order according to its ability.

Limited inventory, how to prevent oversold?

Generally speaking, the second kill goods are low price limited, and the number of visits far exceeds the number of inventory, only a very few people succeed. If you sell more than you have in stock, it’s oversold.

Generally speaking, the process of inventory deduction is as follows:

** Reads the inventory table, determines the inventory, and then deducts the inventory. ** However, heavy traffic concurrent requests to the database in a split second may cause the database to crash.

Because the essence of seckilling is to grab inventory. The database may crash if every second kill user visits the database to check the inventory and then deducts the inventory.

MySQL database can support 1000 QPS, while Redis can support 100,000 QPS. Therefore, we can load the inventory information into Redis, transfer the MySQL access pressure to Redis, and directly judge and deduct the inventory through Redis.

** In fact, Weibo, Alibaba, Baidu, Meituan and Pinduoduo are all using Redis. **Redis is now a standard part of Internet projects and is frequently asked in interviews. The principle behind using Redis is:

  1. Cache inventory information, most data read requests are blocked by Redis, protecting MySQL
  2. Checking Redis inventory and deducting Redis inventory are two steps. Lua scripts combine these two steps into one whole to ensure atomic operation
  3. Even if the Redis side line is ready to create the order, you need to check it again when you go to MySQL.

About how to ensure system stability and high availability, the principles of system design, Redis and the second kill process knowledge points and technical difficulties, TMD senior architect Ouyang Xiu in the second kill project actual combat are very clear, interested partners can go to the free trial.