A global inventory control method and system in a distributed environment
By using event message-based streaming statistics methods in distributed architecture online trading systems, the problem of difficult access to global data views after inventory split is solved, quasi-real-time update of global inventory and dynamic flow control are realized, and the system is improved Stability and inventory management efficiency.
Patent Information
- Application Number
- CN202011036318.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-27
- Publication Date
- 2024-12-20
- Estimated Expiration
- 2040-09-27
AI Technical Summary
In a distributed online trading system, it is difficult to obtain a complete data view in a timely manner from a global perspective after inventory is split, affecting management operations and decision-making.
Using a streaming statistics method based on event messages, by receiving client requests, generating order-related information, sending it to a message queue, listening to the queue for periodic summary statistics, calculating global inventory, and dynamically controlling transaction speed based on inventory volume to achieve quasi-real-time global inventory control.
In a high concurrent trading environment, the global inventory is updated in a quasi-real-time and accurate control, which improves system stability. The dynamic flow control strategy ensures that when there is less inventory, it switches to the serial trading mode, reducing system pressure.
Smart Images

Figure CN112102040B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to an online trading system with a distributed architecture, and in particular to a global inventory control method and system in a distributed environment. Background Art
[0002] With the development of science and technology, more and more real economies are developing in the form of e-commerce. The continuous growth of the number of users has led to higher and higher requirements for the concurrent performance of online trading systems. Without considering performance, the increase or decrease of inventory can be achieved directly by locking a single piece of data in the database table. However, the huge population base in China has brought huge pressure to the access of the system. In order to improve performance, we often adopt a concurrent mode. In a high-concurrency mode, since multiple users can place orders at the same time, it will cause great pressure on the online trading system. Therefore, in recent years, customer-oriented online trading systems have gradually evolved from centralized architecture to distributed architecture. Specifically, the system functions have been vertically split into front-end, back-end and database layers, and the back-end application logic layer and database layer have also gradually realized distributed architecture. With the introduction of distributed data architectures such as sub-libraries and sub-tables, it is inevitable to split the data of the same logical entity horizontally. From the perspective of overall system operation and maintenance, an overall data statistical view is still required.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art: since the inventory is split, a complete data view cannot be obtained in a timely manner from a global perspective, which is not conducive to the management and operation party to control and make decisions. Summary of the invention
[0004] The embodiment of the present invention provides a global inventory control method and system in a distributed environment, so as to obtain an inventory statistical data view from a global perspective.
[0005] To achieve the above objectives, in a first aspect, an embodiment of the present invention provides a global inventory control method in a distributed environment, which includes:
[0006] Receive purchase requests or return requests sent by the user's client;
[0007] The inventory of the current data shard is consumed according to the purchase request, or the inventory of the current data shard is increased according to the return request, an order and order-related information are generated, and the order-related information is sent to a designated message queue; wherein the order-related information includes: the consumed inventory corresponding to the purchase request, or the increased inventory corresponding to the return request;
[0008] Monitoring the order-related information of the designated message queue, performing summary statistics according to a preset period, and obtaining a transaction summary statistical result, wherein the transaction summary statistical result is the sum of the inventory of transactions within the preset period;
[0009] The transaction summary statistical result is read, the latest global inventory is calculated according to the transaction summary statistical result, and saved in the global inventory table.
[0010] In a second aspect, an embodiment of the present invention provides a global inventory control system in a distributed environment, which includes:
[0011] The dynamic flow control module includes a receiving and forwarding submodule, which is used to receive a purchase request or a return request sent by a user's client;
[0012] An order service module, configured to consume the inventory of the current data shard according to the purchase request, or increase the inventory of the current data shard according to the return request, generate an order and order-related information, and send the order-related information to a designated message queue; wherein the order-related information includes: the consumed inventory corresponding to the purchase request, or the increased inventory corresponding to the return request;
[0013] A streaming inventory statistics module is used to monitor the order-related information of the designated message queue, perform summary statistics according to a preset period, and obtain a transaction summary statistics result, wherein the transaction summary statistics result is the sum of the inventory of transactions within the preset period;
[0014] The inventory update module is used to read the transaction summary statistical results, calculate the latest global inventory according to the transaction summary statistical results, and save it in the global inventory table.
[0015] In a third aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the global inventory control method in a distributed environment as described above.
[0016] In a fourth aspect, an embodiment of the present invention provides a computer device, comprising:
[0017] one or more processors;
[0018] A storage device for storing one or more programs;
[0019] When the one or more programs are executed by the one or more processors, the one or more processors implement the global inventory control method in a distributed environment as described above.
[0020] The above technical solution has the following beneficial effects:
[0021] The embodiment of the present invention proposes a streaming statistics method based on event messages for a global inventory view under a data storage structure designed with separate libraries and tables in a distributed application environment, and designs a flexible flow control strategy based on the view to dynamically control the transaction speed through inventory changes and improve the stability of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0023] Figure 1 is a schematic diagram of a concurrent transaction system architecture of an embodiment of the present invention;
[0024] Figure 2 is a flow chart of a global inventory control method in a distributed environment according to a first embodiment of the present invention;
[0025] Figure 3 is a detailed flow chart of step S260 of an embodiment of the present invention;
[0026] Figure 4 is a functional block diagram of a global inventory control system in a distributed environment according to an embodiment of the present invention;
[0027] Figure 5 is a functional block diagram of another global inventory control system in a distributed environment according to an embodiment of the present invention;
[0028] Figure 6 It is a flow chart of the design of the streaming inventory statistics module and its processing flow chart of the embodiment of the present invention;
[0029] Figure 7 is an architecture diagram of an inventory update module and a dynamic flow control module according to an embodiment of the present invention;
[0030] Figure 8 It is a functional block diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0031] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0032] Terminology explanation:
[0033] Stream processing: A general term for a class of technologies that process streaming data in real time without requiring it to land.
[0034] Apache Kafka: An open source distributed messaging middleware that supports stream processing.
[0035] Service: In the IT field, it refers to a mechanism that provides specific functions through a predefined interface.
[0036] The embodiment of the present invention aims to perform streaming statistics on shard inventories scattered on multiple data shards in a distributed environment, provide a quasi-real-time global inventory view, and implement a dynamic flow control strategy based on this view, so as to achieve more accurate global inventory control while taking into account high concurrent transactions.
[0037] The embodiment of the present invention proposes a statistical method for a global inventory view in a distributed environment, and a flow control strategy based on the view.
[0038] For an online trading system adopting a dual-ledger model, an embodiment of the present invention proposes a solution for managing global inventory and flow control. The main functions of the embodiment of the present invention include:
[0039] 1) Ensure quasi-real-time and accurate updates of global inventory without sacrificing concurrency performance or affecting existing transactions;
[0040] 2) According to the global inventory and current transaction volume, the inventory threshold of the flow control switching mode is made dynamic, so that when the inventory is low or a large amount is consumed in a short period of time, the parallel transaction mode can be switched to the serial transaction mode to improve the stability of the system.
[0041] With the increasing popularity of the Internet and the increase in the number of terminal users, the architectural design of online commodity trading systems has also undergone a transformation from centralized to distributed architecture in order to meet the needs of a large number of users to provide services online at the same time. Specifically, application services that contain business processing logic have generally adopted a distributed architecture to meet the requirements of horizontal expansion and high availability. However, with the continuous increase in the number of concurrent users, a single database has gradually become a bottleneck restricting the overall throughput of the system. Therefore, the industry has divided the database that stores business data according to the business transaction chain, splitting it from a single database and a single table into sub-databases and sub-tables to increase the degree of concurrency at the database level and improve the overall throughput of the system.
[0042] Compared with the traditional single database and single table, the split database and split table splits the data of the same logical entity into multiple parts and stores them in multiple different physical databases or physical tables. There is no association between the different parts of the data in the current business transaction chain (for example, for the order transaction of the online shopping system, since each order transaction only involves a single user account, the user account table can be split according to the user account). After the split, the concurrency of the database layer is improved for this type of business transaction. Similarly, from the perspective of improving concurrency, for the inventory data of the goods that need to be obtained simultaneously by concurrent transactions, the split method can also be used to disperse the resources into multiple copies to achieve the purpose of supporting multiple people to obtain it at the same time. The system architecture at this time is as follows: Figure 1 As shown, Figure 1 It is a schematic diagram of the system architecture of concurrent transactions in an embodiment of the present invention.
[0043] In this system architecture, since the commodity inventory is dispersed across multiple data shards, there are two ways to obtain the current overall inventory status view from a global perspective during system operation. The first is to initiate queries to each inventory shard and collect query results. The second method is to calculate and count the transaction information that has occurred to obtain the consumed inventory change, and then calculate it with the total inventory prepared in advance to obtain the current inventory value. In reality, from the perspective of operational management, this overall view often needs to be updated frequently. At this time, the pressure on the database caused by the first method cannot be ignored. The technical solution of the embodiment of the present invention adopts the second method.
[0044] Embodiment 1
[0045] Figure 2 1 is a flow chart of a global inventory control method in a distributed environment according to the first embodiment of the present invention. Figure 2 As shown, the method includes:
[0046] S110: receiving a purchase request or a return request sent by a user's client.
[0047] S120: Consume the inventory of the current data shard according to the purchase request, or increase the inventory of the current data shard according to the return request, generate an order and order-related information, and send the order-related information to a designated message queue; wherein the order-related information includes: the consumed inventory corresponding to the purchase request, or the increased inventory corresponding to the return request.
[0048] In this step, the generation of an order is the reason for the change in inventory when the system is running. Depending on the system, it may be that a user places an order to purchase a product, or that a user initiates a return request.
[0049] S130: Monitor order-related information of a designated message queue, perform summary statistics according to a preset period, and obtain transaction summary statistics results, which are the sum of inventories of transactions within the preset period.
[0050] S140: Read the transaction summary statistics results, calculate the latest global inventory according to the transaction summary statistics results, and save it in the global inventory table.
[0051] The embodiment of the present invention provides a statistical method for a global inventory view for a distributed data storage structure with multiple data shards. The method performs streaming processing based on event messages and can achieve quasi-real-time statistics of global inventory without affecting core business logic.
[0052] Embodiment 2
[0053] In a further embodiment, Figure 2 The method shown also includes the following steps: S150: controlling the transaction speed of subsequent transactions based on the transaction summary statistics, the remaining inventory and the preset inventory threshold.
[0054] In some embodiments, step S150 may specifically include executing any one or more of the following steps:
[0055] S151: On the premise that the online commodity trading system or the online shopping system is normal, if the current remaining inventory is greater than or equal to the preset inventory threshold, no intervention is performed; if the current remaining inventory is less than the preset inventory threshold, the parallel transaction mode is switched to the serial transaction mode; wherein the current remaining inventory is calculated according to the transaction summary statistics result;
[0056] S152: When the response speed of the online commodity transaction system or the online shopping system is lower than a preset response speed threshold, directly switching to a serial transaction mode;
[0057] S153: when a purchase request exceeding a first preset purchase amount is received within a preset time period, the serial switching threshold is increased to control the transaction speed;
[0058] S154: When a purchase request exceeding a second preset purchase amount is received within a preset time period, immediately switch to the serial transaction mode and pause to wait for catching up; wherein the second preset purchase amount is greater than the first preset purchase amount.
[0059] Embodiment 3
[0060] In a further embodiment, the method of the embodiment of the present invention may further include the following steps: S160: dynamically updating the inventory threshold value according to periodic transaction summary statistics.
[0061] Figure 3 FIG. 2 is a detailed flow chart of step S260 of an embodiment of the present invention. Figure 3 As shown, step S160 specifically includes the following steps:
[0062] S161: After receiving the difference between the purchase quantity and the return quantity in each preset period, additionally accumulating the difference between the purchase quantity and the return quantity in the most recent first time period; wherein the first time period is greater than the preset period;
[0063] S162: Calculate the net amount standard deviation based on the net amount of inventory change in the most recent second time period, where the net amount standard deviation represents the degree of fluctuation of the net amount of inventory change in the most recent second time period; wherein the second time period is greater than the first time period;
[0064] S163: setting corresponding threshold multipliers according to different fluctuation levels;
[0065] S164: Multiply the net amount of inventory change in the most recent first time period by the threshold multiplier to obtain a dynamically controlled inventory threshold.
[0066] Embodiment 4
[0067] In a further embodiment, the method of the embodiment of the present invention may further include the following steps:
[0068] S171: When it is determined that no new transaction statistics data included in the transaction summary statistics result is received within the preset time period, switching to the serial transaction mode;
[0069] S171: When the transaction summary statistics are detected again, determine whether the streaming statistics are consistent with the serially recorded inventory based on the timestamp and heartbeat response of the transaction statistics. If they are consistent, switch back to the parallel transaction mode.
[0070] In a further embodiment, the method of the embodiment of the present invention may further include the following steps:
[0071] S181: When the total available inventory is lower than the dynamic inventory threshold, the purchase channel is temporarily closed;
[0072] S182: After waiting for the transaction summary statistics to be completely equalized, switch to the serial transaction mode, that is, the mode of serially updating the available inventory, and open the purchase channel again.
[0073] Embodiment 5
[0074] Figure 4 1 is a functional block diagram of a global inventory control system in a distributed environment according to an embodiment of the present invention. Figure 4 As shown, the control system 200 includes:
[0075] The dynamic flow control module 210 includes a receiving and forwarding submodule 211, which is used to receive a purchase request or a return request sent by a user's client;
[0076] The order service module 220 is used to consume the inventory of the current data shard according to the purchase request, or increase the inventory of the current data shard according to the return request, generate an order and order-related information, and send the order-related information to a designated message queue; wherein the order-related information includes: the consumed inventory corresponding to the purchase request, or the increased inventory corresponding to the return request;
[0077] The streaming inventory statistics module 230 is used to monitor order-related information of a specified message queue, perform summary statistics according to a preset period, and obtain a transaction summary statistics result, which is the sum of the inventory of transactions within the preset period;
[0078] The inventory update module 240 is used to read the transaction summary statistics results, calculate the latest global inventory according to the transaction summary statistics results, and save it in the global inventory table.
[0079] Figure 5 is a functional block diagram of another global inventory control system in a distributed environment according to an embodiment of the present invention. Figure 5 As shown, in some embodiments, the dynamic flow control module 210 may also include a transaction speed control submodule 212, which is used to control the transaction speed of subsequent transactions based on transaction summary statistics, remaining inventory and a preset inventory threshold.
[0080] In some embodiments, the transaction speed control submodule 212 is specifically configured to perform any one or more of the following:
[0081] Under the premise that the online commodity trading system or online shopping system is normal, if the current remaining inventory is greater than or equal to the preset inventory threshold, no intervention is performed; if the current remaining inventory is less than the preset inventory threshold, the parallel transaction mode is switched to the serial transaction mode; wherein the current remaining inventory is calculated based on the transaction summary statistics;
[0082] When the response speed of the online commodity trading system or the online shopping system is lower than the preset response speed threshold, it directly switches to the serial transaction mode;
[0083] When a purchase request exceeding a first preset purchase quantity is received within a preset time period, the inventory threshold for performing serial switching is increased to control the speed of receiving purchase requests and generating orders;
[0084] When a purchase request exceeding a second preset purchase amount is received within a preset time period, the mode is immediately switched to the serial transaction mode, the processing of the purchase request is suspended, and waiting is made to catch up; wherein the second preset purchase amount is greater than the first preset purchase amount.
[0085] In some embodiments, the dynamic flow control module 210 further includes a dynamic threshold updating submodule 213 for dynamically updating the inventory threshold according to periodic transaction statistics.
[0086] In some embodiments, the dynamic threshold updating submodule 213 is specifically used to:
[0087] After receiving the difference between the purchase quantity and the return quantity in each preset period, the difference between the purchase quantity and the return quantity in the most recent first time period is additionally accumulated; wherein the first time period is greater than the preset period;
[0088] Then, the net amount standard deviation is calculated based on the net amount of inventory change in the most recent second time period, and the net amount standard deviation represents the degree of fluctuation of the net amount of inventory change in the most recent second time period; wherein the second time period is greater than the first time period;
[0089] According to different fluctuation levels, set the corresponding threshold multiplier;
[0090] The net amount of inventory change in the most recent first time period is multiplied by the threshold multiplier to obtain the dynamically controlled inventory threshold.
[0091] In some embodiments, the dynamic flow control module 210 further includes an abnormality detection switching submodule 214, which can be used to:
[0092] When it is determined that no new transaction statistics data included in the transaction summary statistics result has been received within the preset time period, switching to the serial transaction mode;
[0093] When the transaction summary statistics are detected again, the streaming statistics are judged whether they are consistent with the serially recorded inventory based on the timestamp and heartbeat response of the transaction statistics. If they are consistent, the parallel transaction mode is switched back.
[0094] In some embodiments, the dynamic flow control module 210 may include a purchase channel control submodule 215 for:
[0095] When the total available inventory is lower than the dynamic inventory threshold, the purchase channel is temporarily closed;
[0096] After waiting for the transaction summary statistics to be completely balanced, switch to the mode of serially updating the available inventory and open the purchase channel again.
[0097] In some embodiments, the four services of dynamic flow control service, order service, streaming statistics service, and inventory update service can be separately deployed on different servers.
[0098] In some other embodiments, the dynamic flow control service, order service and inventory update service are deployed and run on the same server, and each purchase request must be judged by the dynamic flow control service to determine whether the transaction is currently allowed or whether parallel transactions are allowed. After the judgment, it will reach the order service for processing.
[0099] The order service communicates with the streaming statistics service and the inventory update service through message queues, so these three services can be deployed and run separately.
[0100] In some embodiments, there are four hardware execution entities, namely application server (dynamic flow control service, order service, inventory update service), message queue server (Kafka), stream processing server (streaming statistics service), and database server. In terms of interaction, the application server will read and write the database, and will also send order messages to the message queue. The stream processing server consumes messages from the message queue, generates summary statistics messages and writes them to the message queue. These messages are consumed by the application server and update the global inventory to the database.
[0101] The following is a more detailed description:
[0102] Message-based streaming inventory statistics module:
[0103] In order to avoid the pressure on the database caused by frequent queries of multiple data shards, an embodiment of the present invention adopts an event message-based method to perform streaming statistics. Specifically, for services related to inventory changes on the original transaction chain, an event message is sent to the order message queue after successful execution. The message content includes the consumed or increased inventory (such as the number of purchased goods in the order transaction, the number of goods released in the order cancellation transaction, etc.). A statistical module is used to periodically summarize and count the number of goods involved in the above message to obtain the change in the inventory consumption quantity. This change will serve as the control basis for the subsequent flow control module. The processing steps of a statistical process of an embodiment of the present invention include:
[0104] The user initiates an order (or cancels an order); the client purchase request can directly enter the dynamic flow control service, which will judge and forward it to the order service for subsequent processing.
[0105] The order service deducts or increases the inventory of the current data shard, generates an order, and sends order-related information (including the quantity of goods) to the order message queue. Purchasing an order corresponds to deducting inventory, and canceling an order corresponds to increasing inventory. The order-related information is generated by the order service when the order is generated, and sent to the order message queue. The order message queue records the information of each order for the streaming inventory statistics module to perform statistics.
[0106] The streaming inventory statistics service / module monitors the order-related information of the order message queue, summarizes and counts it according to a specific period (for example, but not limited to one second), and sends the statistical results of the number of commodity transactions within the preset period (for example, the sum of the purchase quantity in the last second) to the downstream message queue. The object of the summary statistics is the number of commodities in each order, that is, the change in the corresponding inventory. In this embodiment, two message queues with different business meanings are involved, namely the order message queue and the summary statistics message queue. After the order information is counted by the streaming inventory statistics service, the result is generated to the summary statistics message queue.
[0107] Streaming inventory statistics module design and its processing flow Figure 6 shown.
[0108] Since the streaming inventory statistics module is based on event message streams, it is less invasive to the existing business processing logic, and with the highly available message queue, it realizes the separation of statistics and transactions. To ensure the persistent storage of event messages and facilitate streaming statistics, the message queue can use the Apache Kafka message queue, and the streaming statistics can use the Kafka streams stream processing framework that supports end-to-end Exactly-Once guarantees, which can ensure that event messages and statistical messages are neither repeated nor lost in the message queue and during the entire processing process.
[0109] Inventory Update Module:
[0110] The inventory update module calculates the latest global inventory by reading the transaction summary statistics results of the streaming inventory statistics module, that is, the summary statistics result message, and saves it to the global inventory table.
[0111] Dynamic flow control module:
[0112] The dynamic flow control module is used to directly receive the purchase request and return request from the client. By default, the dynamic flow control module does not intervene in the client request and directly forwards it to the order service to execute the transaction in parallel. The dynamic flow control module makes decisions based on the transaction summary statistics of the streaming inventory statistics module, combined with the current business remaining inventory and the preset relevant warning thresholds, and adopts appropriate control strategies (parallel forwarding or serial forwarding) for subsequent transactions. Specifically, when the current inventory is sufficient, priority is given to providing the maximum parallelism for user requests to achieve efficient transaction processing. When the inventory is small, or the purchase volume of goods is large in a short period of time, and the inventory has a tendency to be sold out quickly, priority is given to controlling concurrent user requests, and the inventory is updated more accurately by changing to serial processing, while also reducing the concurrent pressure of the system. Because in the design of sharding, the inventory is dispersed in each data shard. When the remaining inventory is small, there may be a situation where the inventory of some shards is 0, so the application logic may also need to implement more complex inventory search logic for this situation. At this time, the dynamic flow control module releases the transaction request in serial mode, which is also a more reliable way to reduce the pressure of application services. The architecture diagram of the inventory update module and dynamic flow control module is as follows: Figure 7 shown.
[0113] The overall design ideas are as follows:
[0114] 1) Under the premise that the online commodity trading system or online shopping system is normal, the maximum purchase quantity is controlled, which means that no intervention is made when the inventory is large, and it is switched to serial when the inventory is small, that is, switching from parallel trading mode to serial trading mode.
[0115] The above-mentioned normal means that the interactive response time between the various deployed hardware in the system is within an acceptable range. For example, when the order service generates an order, the information of the order is summarized by the streaming inventory statistics service within one second, and then reflected in the changes of the global inventory through the inventory update service. This is normal. If it exceeds 5 seconds (the time length is configurable) and is not reflected in the global inventory, it is considered abnormal.
[0116] Among them, the parallel mode means that when the inventory data is sharded, multiple purchase requests can be processed by the order module at the same time, and different inventory data shards can be updated respectively. The serial mode means that all purchase requests can only be processed one by one in chronological order.
[0117] 2) When the online commodity trading system or online shopping system responds slowly, it directly switches to serial transaction mode.
[0118] 3) Buying in large quantities in a short period of time, raising the serial switching threshold, controlling the speed of receiving purchase requests and generating orders. In this embodiment, the default mode is parallel mode under normal circumstances. When the global inventory decreases to a critical point, it is necessary to switch to serial mode. The inventory at this critical point is the serial switching threshold. Once switched to serial mode, it is equivalent to controlling the speed.
[0119] 4) For large-volume purchases in a short period of time, the system immediately switches to the serial transaction mode, suspends the processing of purchase requests, and waits for the balance to be reached. In this embodiment, after suspending the processing of purchase requests, the system waits for the global inventory to be updated, and the system response time is normal, the balance can be considered.
[0120] 5) Dynamically determine the parallel / serial switching inventory critical point (inventory threshold) based on the current transaction status to achieve flow control based on dynamic inventory.
[0121] Based on the above considerations, the design of the dynamic flow control module also includes the following parts.
[0122] Dynamic threshold control algorithm:
[0123] Since the streaming inventory statistics module provides periodic transaction statistics, the dynamic flow control module can design a threshold algorithm based on these basic data to dynamically update the inventory threshold. Once the current remaining inventory is lower than the threshold, the flow control strategy is switched to the serial transaction mode. There are many dynamic threshold algorithms based on transaction statistics data, and only one example is given here for illustration.
[0124] After the application system receives the difference between the purchase and return quantities per second from the streaming inventory statistics module, it additionally accumulates the difference between the purchase and return quantities in the most recent time period (time period) (such as 1 minute) as the net inventory change within the period. The specific accumulated time interval granularity can be adjusted according to the degree of control sophistication. Based on the net inventory change in multiple consecutive accumulated periods, the net inventory change in future periods can be predicted. For this type of prediction based on event sequences, the exponential smoothing prediction method in statistics can be used. According to the fluctuation of the net inventory change, one, two or three exponential smoothing methods can be used for prediction. Generally speaking, first exponential smoothing is used to predict time series with nearly horizontal trends, second exponential smoothing is used to predict time series with linear trends, and third exponential smoothing is used to predict time series that can reflect seasonal characteristics. The basic formula of the exponential smoothing prediction method is:
[0125] S t =α·y t +(1-α)S t-1
[0126] Where S t is the smoothing value of period t, α is the smoothing constant, yt is the actual value in period t, S t-1 is the smoothed value of period t-1.
[0127] The formula for first-order exponential smoothing is:
[0128] S t+1 =a·y t +(1-a)S t
[0129] The formula for first-order exponential smoothing is similar to the basic formula for exponential smoothing, but the forecast value for period t+1 is the weighted average of the observed value for period t and the forecast value for period t.
[0130] The formula for quadratic exponential smoothing is:
[0131]
[0132]
[0133]
[0134]
[0135] F t+m =a t +b t m........................................(5)
[0136] The first exponential smoothing directly uses the smoothed value as the predicted value, and the second exponential smoothing rule is a linear smoothing model obtained by correcting the trend with the smoothed value.
[0137] The brief prediction steps using quadratic exponential smoothing are as follows:
[0138] Step 1: According to the fluctuation characteristics of the net inventory change, select the initial smoothing constant (the smoothing constant is close to 1 when the fluctuation is large, and it can be close to 0 when the fluctuation is small);
[0139] Step 2: Substitute the net inventory change of each period into the exponential smoothing formula in chronological order to calculate the smoothed value;
[0140] Step 3: Substitute the first smoothing value into the second exponential smoothing formula, calculate the second smoothing value, and then calculate the forecast value F for the next m periods. t+m .
[0141] Finally, according to the predicted F t+m The net inventory change of the next cycle is used as the threshold for dynamic control. In general, m can be taken as 1, that is, the net inventory change of the next cycle is used as the threshold based on the current forecast.
[0142] The above application system is a whole application system with a dynamic flow control module, an order module, a streaming inventory statistics module and an inventory update module.
[0143] Statistical system anomaly detection and response:
[0144] Since the update of the application's global inventory view depends on the sending of event messages for the corresponding transactions and the aggregation processing of the streaming inventory statistics module, if an exception occurs in this process, although in theory it will not have a direct impact on the main order service, it may cause the global inventory to be updated untimely, and then lead to the failure of the flow control logic. Therefore, the application will determine whether the background streaming data statistics module is in a normal state based on a series of conditions, such as if no new statistics are received within 5 seconds. At this time, the application will switch to serial mode, that is, it will no longer rely on the data of the background streaming inventory statistics module, but will update the available inventory synchronously at the same time as each purchase and return transaction occurs based on the latest global statistics. At this time, some concurrency performance is sacrificed to ensure the security and accuracy of the system inventory.
[0145] When the application system detects the recovery of the background streaming inventory statistics module again (receives the message sent by it), it will determine whether the streaming statistics data is consistent (tied) with the inventory recorded serially by the flow control module itself based on a series of conditions, such as the statistics timestamp and heartbeat response. Once the application determines that the statistics of the background system are close to tying, it will switch back to the concurrent purchase and return mode based on the background statistics.
[0146] Critical inventory cash out:
[0147] Once the total available inventory falls below a new dynamic threshold, the app will temporarily close the purchase channel.
[0148] After waiting for the background statistics to completely catch up, the application will switch to the mode of serially updating the available inventory and open the purchase channel again. In this way, the system can safely sell all the goods close to the critical time.
[0149] The beneficial effects brought by the above technical solution of the embodiment of the present invention include:
[0150] The embodiment of the present invention provides a statistical method for a global inventory view for a distributed data storage structure with multiple data shards. The method performs streaming processing based on event messages and can achieve quasi-real-time statistics of global inventory without affecting the core business logic. A solution for flow control based on available inventory is also proposed.
[0151] The service that undertakes the core transaction logic in the embodiment of the present invention needs to send an event message to a persistent message queue after successful execution, and the message content includes the quantity information of the goods executed this time.
[0152] The embodiment of the present invention performs periodic aggregation statistics on all event messages in a streaming statistics manner, and uses the aggregation results as the control basis of the flow control logic.
[0153] The flow control module of the embodiment of the present invention provides two modes, parallel and serial, and dynamically determines the switching threshold based on aggregated transaction statistics. When the available inventory is small or a large amount of inventory is consumed in a short period of time, the flow control mode is switched to serial, thereby improving the stability of the system.
[0154] The flow control module of the embodiment of the present invention automatically determines that the streaming inventory statistics module has failed when the aggregated statistical message times out. To ensure the flow control effect, the serial mode is automatically enabled at this time to update the inventory table in a strongly consistent manner. When the streaming inventory statistics module is restored and the serial statistical inventory is close to the streaming statistical inventory, it switches back to the parallel mode.
[0155] Embodiment 6
[0156] The embodiment of the present invention further provides an electronic device, such as Figure 8 As shown, it includes one or more processors 301 , a communication interface 302 , a memory 303 and a communication bus 304 , wherein the processor 301 , the communication interface 302 , and the memory 303 communicate with each other via the communication bus 304 .
[0157] Memory 303, used for storing computer programs;
[0158] The processor 301 is used to execute the program stored in the memory 303 to implement the following steps:
[0159] S110: receiving a purchase request or a return request sent by a user's client;
[0160] S120: Consume the inventory of the current data shard according to the purchase request, or increase the inventory of the current data shard according to the return request, generate an order and order-related information, and send the order-related information to a designated message queue; wherein the order-related information includes: the consumed inventory corresponding to the purchase request, or the increased inventory corresponding to the return request;
[0161] S130: Monitor order-related information in a designated message queue, perform summary statistics according to a preset period, and obtain a transaction summary statistical result, where the transaction summary statistical result is the sum of the inventory of transactions within the preset period;
[0162] S140: Read the transaction summary statistics results, calculate the latest global inventory according to the transaction summary statistics results, and save it in the global inventory table.
[0163] In some exemplary embodiments, the processor 301 is also used to implement the following steps when executing the program stored in the memory 303: controlling the transaction speed of subsequent transactions based on the transaction summary statistics, the remaining inventory of the current business and the preset inventory threshold.
[0164] In some exemplary embodiments, the processor 301 is also used to implement the following steps when executing the program stored in the memory 303: S150: Control the transaction speed of subsequent transactions based on the transaction summary statistics, the remaining inventory of the current business and the preset inventory threshold.
[0165] In some exemplary embodiments, the processor 301 is further configured to implement any one or more of the following steps when executing the program corresponding to step S150 stored in the memory 303:
[0166] S151: Under the premise that the online commodity trading system or the online shopping system is normal, when the inventory is greater than or equal to the preset inventory threshold, no intervention is performed; when the inventory is less than the preset inventory threshold, the parallel transaction mode is switched to the serial transaction mode;
[0167] S152: When the response speed of the online commodity transaction system or the online shopping system is lower than a preset response speed threshold, directly switching to a serial transaction mode;
[0168] S153: when a purchase request exceeding a first preset purchase quantity is received within a preset time period, the inventory threshold for performing serial switching is increased to control the speed of receiving purchase requests and generating orders;
[0169] S154: When a purchase request exceeding a second preset purchase amount is received within a preset time period, immediately switch to the serial transaction mode, suspend processing of the purchase request, and wait for catching up; wherein the second preset purchase amount is greater than the first preset purchase amount.
[0170] In some exemplary embodiments, the processor 301 is further configured to implement the following steps when executing a program stored in the memory 303: S160: dynamically updating the inventory threshold according to periodic transaction summary statistics.
[0171] In some exemplary embodiments, the processor 301 is further configured to implement the following steps when executing the program corresponding to step S160 stored in the memory 303:
[0172] S161: After receiving the difference between the purchase quantity and the return quantity in each preset period, additionally accumulating the difference between the purchase quantity and the return quantity in the most recent first time period; wherein the first time period is greater than the preset period;
[0173] S162: Calculate the net amount standard deviation based on the net amount of inventory change in the most recent second time period, where the net amount standard deviation represents the degree of fluctuation of the net amount of inventory change in the most recent second time period; wherein the second time period is greater than the first time period;
[0174] S163: setting corresponding threshold multipliers according to different fluctuation levels;
[0175] S164: Multiply the net amount of inventory change in the most recent first time period by the threshold multiplier to obtain a dynamically controlled inventory threshold.
[0176] In some exemplary embodiments, the processor 301 is further configured to implement the following steps when executing a program stored in the memory 303:
[0177] S171: When it is determined that no new transaction summary statistical result included in the transaction summary statistical result is received within the preset time period, switching to the serial transaction mode;
[0178] S171: When the transaction summary statistics are detected again, determine whether the streaming statistics are consistent with the serially recorded inventory based on the timestamp and heartbeat response of the transaction statistics. If they are consistent, switch back to the parallel transaction mode.
[0179] In some exemplary embodiments, the processor 301 is further configured to implement the following steps when executing a program stored in the memory 303:
[0180] S181: When the total available inventory is lower than the dynamic inventory threshold, the purchase channel is temporarily closed;
[0181] S182: After waiting for the transaction statistics to be completely equalized, switch to the serial transaction mode, that is, the mode of updating the available inventory, and open the purchase channel again.
[0182] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The communication interface is used for communication between the above electronic device and other devices.
[0183] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0184] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0185] Embodiment 7
[0186] An embodiment of the present invention further provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, each step of any of the above-mentioned global inventory control methods in a distributed environment is implemented.
[0187] The various illustrative logic blocks or units described in the embodiments of the present invention can be implemented or operated by a general-purpose processor, a digital signal processor, an application-specific integrated circuit (ASIC), a field programmable gate array or other programmable logic device, a discrete gate or transistor logic, a discrete hardware component, or any combination of the above. The general-purpose processor can be a microprocessor, and optionally, the general-purpose processor can also be any conventional processor, controller, microcontroller or state machine. The processor can also be implemented by a combination of computing devices, such as a digital signal processor and a microprocessor, a plurality of microprocessors, one or more microprocessors combined with a digital signal processor core, or any other similar configuration.
[0188] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0189] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, electronic device, and readable storage medium embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0190] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims
1. A global inventory control method in a distributed environment, characterized in that: include: Receive purchase requests or return requests sent by the user's client; The inventory of the current data shard is consumed according to the purchase request, or the inventory of the current data shard is increased according to the return request, an order and order-related information are generated, and the order-related information is sent to a designated message queue; wherein the order-related information includes: the consumed inventory corresponding to the purchase request, or the increased inventory corresponding to the return request; wherein the order is generated as a reason for the inventory change when the system is running, specifically in different systems, including a user placing an order to purchase a product, or a user initiating a return request; Monitoring the order-related information of the designated message queue, performing summary statistics according to a preset period, and obtaining a transaction summary statistical result, wherein the transaction summary statistical result is the sum of the inventory of transactions within the preset period; Read the transaction summary statistics result, calculate the latest global inventory according to the transaction summary statistics result, and save it in the global inventory table; Controlling the transaction speed of subsequent transactions according to the transaction summary statistics, the remaining inventory and the preset inventory threshold; The controlling of the transaction speed of subsequent transactions according to the transaction summary statistics, the remaining inventory and the preset inventory threshold specifically includes executing any one or more of the following: Under the premise that the online commodity trading system or the online shopping system is normal, if the current remaining inventory is greater than or equal to the preset inventory threshold, no intervention is performed; if the current remaining inventory is less than the preset inventory threshold, the parallel transaction mode is switched to the serial transaction mode; wherein the current remaining inventory is calculated according to the transaction summary statistical result; When the response speed of the online commodity trading system or the online shopping system is lower than the preset response speed threshold, it directly switches to the serial transaction mode; When a purchase request exceeding a first preset purchase quantity is received within a preset time period, the inventory threshold for performing serial switching is increased to control the speed of receiving purchase requests and generating orders; When a purchase request exceeding a second preset purchase amount is received within a preset time period, the serial transaction mode is immediately switched to pause processing of the purchase request and wait for the transaction to be equalized; wherein the second preset purchase amount is greater than the first preset purchase amount; According to the periodic transaction summary statistics, the inventory threshold is dynamically updated. Specifically, after the application system receives the difference between the purchase and return quantities per second from the streaming inventory statistics module, it accumulates the difference between the purchase and return quantities in the most recent time period as the net inventory change in the period. The specific accumulated time interval granularity is adjusted according to the degree of control sophistication. Based on the net inventory change in multiple consecutive accumulated periods, the net inventory change in the future period is predicted. For this event sequence-based prediction, the exponential smoothing prediction method is used: S t =α·y t +(1-α)S t-1 Where S t is the smoothing value of period t, α is the smoothing constant, y t is the actual value in period t, S t-1 is the smoothed value of period t-1.
2. The method according to claim 1, characterized in that The method of dynamically updating the inventory threshold according to the periodic transaction summary statistics includes: After receiving the difference between the purchase quantity and the return quantity in each of the preset periods, the difference between the purchase quantity and the return quantity in the most recent first time period is additionally accumulated; wherein the first time period is greater than the preset period; Then, according to the net amount of inventory change in the most recent second time period, a net amount standard deviation is calculated, wherein the net amount standard deviation represents the degree of fluctuation of the net amount of inventory change in the most recent second time period; wherein the second time period is greater than the first time period; According to different fluctuation levels, set the corresponding threshold multiplier; The net amount of inventory change in the most recent first time period is multiplied by the threshold multiplier to obtain a dynamically controlled inventory threshold.
3. The method according to claim 1, characterized in that: Also includes: When it is determined that no new transaction statistics data included in the transaction summary statistics result has been received within the preset time period, switching to the serial transaction mode; When the transaction summary statistics are detected again, the streaming statistics are judged whether they are consistent with the serially recorded inventory based on the timestamp and heartbeat response of the transaction statistics. If they are consistent, the parallel transaction mode is switched back.
4. The method according to claim 1, characterized in that: When the total available inventory is lower than the dynamic inventory threshold, the purchase channel is temporarily closed; After waiting for the transaction summary statistics to completely equalize, switch to serial trading mode and open the purchase channel again.
5. A global inventory control system in a distributed environment, characterized in that: include: The dynamic flow control module includes a receiving and forwarding submodule, which is used to receive a purchase request or a return request sent by a user's client; An order service module, configured to consume the inventory of the current data shard according to the purchase request, or increase the inventory of the current data shard according to the return request, generate an order and order-related information, and send the order-related information to a designated message queue; wherein the order-related information includes: the consumed inventory corresponding to the purchase request, or the increased inventory corresponding to the return request; A streaming inventory statistics module is used to monitor the order-related information of the designated message queue, perform summary statistics according to a preset period, and obtain a transaction summary statistics result, wherein the transaction summary statistics result is the sum of the inventory of transactions within the preset period; An inventory update module, used to read the transaction summary statistics results, calculate the latest global inventory according to the transaction summary statistics results, and save it in the global inventory table; The transaction speed control submodule is specifically used to perform any one or more of the following: Under the premise that the online commodity trading system or the online shopping system is normal, if the current remaining inventory is greater than or equal to the preset inventory threshold, no intervention is performed; if the current remaining inventory is less than the preset inventory threshold, the parallel transaction mode is switched to the serial transaction mode; wherein the current remaining inventory is calculated according to the transaction summary statistical result; When the response speed of the online commodity trading system or the online shopping system is lower than the preset response speed threshold, it directly switches to the serial transaction mode; When a purchase request exceeding a first preset purchase quantity is received within a preset time period, the inventory threshold for performing serial switching is increased to control the speed of receiving purchase requests and generating orders; When a purchase request exceeding a second preset purchase amount is received within a preset time period, the serial transaction mode is immediately switched to pause processing of the purchase request and wait for the transaction to be equalized; wherein the second preset purchase amount is greater than the first preset purchase amount; The threshold update module is used to dynamically update the inventory threshold according to the periodic transaction summary statistics. Specifically, after the application system receives the difference between the purchase and return quantities per second from the streaming inventory statistics module, it accumulates the difference between the purchase and return quantities in the most recent time period as the net inventory change in the period. The specific accumulated time interval granularity is adjusted according to the degree of control sophistication. Based on the net inventory change in multiple consecutive accumulated periods, the net inventory change in the future period is predicted. For this prediction based on event sequence, the exponential smoothing prediction method is used: S t =α·y t +(1-α)S t-1 Where S t is the smoothing value of period t, α is the smoothing constant, y t is the actual value in period t, S t-1 is the smoothed value of period t-1.
6. The system according to claim 5, characterized in that The dynamic threshold updating submodule is specifically used for: After receiving the difference between the purchase quantity and the return quantity in each of the preset periods, the difference between the purchase quantity and the return quantity in the most recent first time period is additionally accumulated; wherein the first time period is greater than the preset period; Then, according to the net amount of inventory change in the most recent second time period, a net amount standard deviation is calculated, wherein the net amount standard deviation represents the degree of fluctuation of the net amount of inventory change in the most recent second time period; wherein the second time period is greater than the first time period; According to different fluctuation levels, set the corresponding threshold multiplier; The net amount of inventory change in the most recent first time period is multiplied by the threshold multiplier to obtain a dynamically controlled inventory threshold.
7. The system according to claim 5, characterized in that The dynamic flow control module further includes an abnormality detection switching submodule, which is used to: When it is determined that no new transaction statistics data included in the transaction summary statistics result has been received within the preset time period, switching to the serial transaction mode; When the transaction summary statistics are detected again, the streaming statistics are judged whether they are consistent with the serially recorded inventory based on the timestamp and heartbeat response of the transaction statistics. If they are consistent, the parallel transaction mode is switched back.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, a global inventory control method in a distributed environment as described in any one of claims 1 to 4 is implemented.
9. A computer device, characterized in that: It includes: one or more processors; A storage device for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the global inventory control method in a distributed environment as described in any one of claims 1-4.
Citation Information
Patent Citations
Inventory deduction method and inventory deduction device
CN105096065A
Fragmented transaction matching method and fragmented transaction matching device
CN105096122A
Distributed database management method and system
CN105930498A
Distributed transaction processing method and system for multi-data sources
CN107329809A
Distributed logistics inventory optimization method based on cloud calculation environment
CN108280538A
