During rush buying, an asynchronous queue is used to process orders, so how to notify users of the order results in real time?

WBOY
Release: 2016-10-17 09:30:14
Original
1949 people have browsed it

When rushing to buy, an asynchronous queue is used to process orders, so how to notify users of the order results in real time?

Reply content:

When rushing to buy, an asynchronous queue is used to process orders, so how to notify users of the order results in real time?

The client uses js to poll an interface to obtain the processing status

The most important thing for rush buying is to ensure strong consistency of inventory data. The instantaneous traffic of rush buying is very large. If you use some relational databases such as MySql, you may not be able to withstand the pressure in this regard. Generally, it is processed in combination with caching middleware, such as redis. Before the rush purchase begins, the product and inventory data are synchronized to redis. All rush purchase operations are processed in redis. An asynchronous task is started in the background to regularly flush the inventory data to the database.
Then start paying for the order. Due to the large traffic, the third-party payment system itself also limits the traffic of the calling application, so what you said here should be what I need to describe next.
Message queue must be used here (that is, what you call asynchronous queue). You can refer to Taobao's Double 11 current limiting measures. In order to protect the system from the impact of high traffic and cause system crash, the message queue has been added. For buffer protection, the system needs to design a window model. The window model will refresh the status of the user's procedures in real time.
For example, after placing an order and preparing to pay, the user will jump to the service window in the service hall. If the window is full at this time, that is, the number of consumers reaches online, then the user needs to start queuing. The system can pop up The waiting window allows the user to wait for a while. Once an idle thread is released, the user can start paying and placing orders.
The above is explained based on the model of taking photos to reduce inventory. If the system you design is to reduce inventory through payment, there will be slight differences. However, such a window is also needed to inform the user of the status. The user's payment is successful in a timely manner, although the payment is not completed in time. The status is returned to the user, and the user can view his window status in real time through a page.

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template