Order asynchronous processing method and system, medium and equipment

By adopting the token bucket mechanism and asynchronous processing method on the e-commerce platform, the server load problem caused by high concurrent snap-ups is solved, and users can promptly sense order status and system load relief.

CN119850301APending Publication Date: 2025-04-18KE COM (BEIJING) TECHNOLOGY CO LTD
View PDF 10 Cites 0 Cited by

Patent Information

Application Number
CN202411944434.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-26
Publication Date
2025-04-18

AI Technical Summary

Technical Problem

In e-commerce platforms, when multiple people rush to buy products at the same time, high concurrency will cause excessive server load, which may cause server paralysis and system downtime, and users will not be able to sense the order status in time.

Method used

The asynchronous processing method is adopted to control the traffic of order requests through the token bucket mechanism. When the quantity of tokens is not less than the purchase quantity, create an order and set the order status to the "Order Creation" status, and then process the persistence of order data and inventory deduction asynchronously.

Benefits of technology

It realizes timely generation of order data under high concurrency conditions. Users can sense the order status in a timely manner and alleviate the server load pressure through asynchronous processing to avoid system crashes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119850301A_ABST
    Figure CN119850301A_ABST
Patent Text Reader

Abstract

The invention provides an order asynchronous processing method and system, a medium and equipment, and the method comprises the steps: receiving an order request sent by a client, the order request carrying commodity identification information of a commodity requested to be purchased and a purchase quantity; determining the number of tokens in a token bucket corresponding to the commodity identification information; in response to the fact that the token number is not smaller than the purchase number, creating a commodity order corresponding to the order request and setting an order state of the commodity order as an in-order-creation state; carrying out asynchronous processing on the commodity order and the inventory of the commodity; wherein the asynchronous processing of the commodity order comprises the step of carrying out persistent processing on order data of the commodity order, and the processing of the inventory of the commodity comprises the step of carrying out deduction processing on the inventory of the commodity based on the purchase quantity. According to the method and the device, the token bucket is used for smoothly controlling the flow of the order request, the influence on the system caused by excessive instantaneous flow is avoided, and the load pressure of the system can be further relieved by asynchronously processing the order.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of network communication and data processing technology, and in particular to an asynchronous processing method, system, medium and device for an order. Background Art

[0002] With the promotion and application of e-commerce platforms, more and more users like to shop online. When multiple people visit the platform or rush to buy a certain product at the same time, it is easy to cause great load pressure on the server of the e-commerce platform due to high concurrency, and may even cause server paralysis and system downtime, and users cannot perceive the order status in time.

[0003] Therefore, how to handle orders from multiple people who are rushing to buy goods at the same time is a technical issue that deserves attention. Summary of the invention

[0004] In order to solve the above technical problems, the embodiments of the present disclosure provide an asynchronous processing method, system, medium and device for an order.

[0005] According to a first aspect of an embodiment of the present disclosure, there is provided an asynchronous processing method for an order, comprising:

[0006] Receive an order request sent by a client, wherein the order request carries the commodity identification information and the purchase quantity of the requested commodity;

[0007] Determine the number of tokens in the token bucket corresponding to the commodity identification information;

[0008] In response to the token quantity being not less than the purchase quantity, creating a commodity order corresponding to the order request and setting the order status of the commodity order to an order creating status;

[0009] Asynchronously processing the commodity order and the inventory of the commodity; wherein the asynchronous processing of the commodity order includes: persisting the order data of the commodity order, and processing the inventory of the commodity includes: deducting the inventory of the commodity based on the purchase quantity.

[0010] According to a second aspect of an embodiment of the present disclosure, there is provided an asynchronous processing device for an order, comprising:

[0011] A first receiving module is used to receive an order request sent by a client, wherein the order request carries the commodity identification information and the purchase quantity of the requested commodity;

[0012] A first determination module, used to determine the number of tokens in the token bucket corresponding to the commodity identification information;

[0013] An order creation module, configured to create a commodity order corresponding to the order request and set the order status of the commodity order to an order creation status in response to the token quantity being not less than the purchase quantity;

[0014] An asynchronous processing module is used to asynchronously process the product order and the inventory of the product; wherein the asynchronous processing of the product order includes: persisting the order data of the product order, and the processing of the inventory of the product includes: deducting the inventory of the product based on the purchase quantity.

[0015] According to a third aspect of an embodiment of the present disclosure, there is provided an asynchronous processing system for an order, the system comprising: an order creation unit, a persistent order unit, and an inventory deduction unit;

[0016] The order creation unit is used to receive an order request sent by a client, wherein the order request carries the commodity identification information and the purchase quantity of the requested commodity; determine the number of tokens in the token bucket corresponding to the commodity identification information; in response to the number of tokens being not less than the purchase quantity, create a commodity order corresponding to the order request and set the order state of the commodity order to the order creation state; push a persistent order message to a first message queue, wherein the first message queue stores at least one persistent order message, and each of the persistent order messages carries the order data of a commodity order;

[0017] The persistent order unit is used to perform batch persistence processing on at least one order data in at least one persistent order message in the first message queue, wherein the batch persistence processing is to write the at least one order data in batches into the order database; after completing the batch persistence processing of the order, push the inventory deduction message to the second message queue, wherein the second message queue stores at least one inventory deduction message, and each inventory deduction message carries the order data of a commodity order;

[0018] The inventory deduction unit is used to determine the total purchase amount of goods corresponding to the at least one order request based on the purchase quantity in the order data carried by at least one inventory deduction message; and perform a one-time inventory deduction operation based on the total purchase amount of goods.

[0019] According to a fourth aspect of an embodiment of the present disclosure, there is provided a computer-readable storage medium, wherein the storage medium stores computer program instructions, and when the computer program instructions are executed, the above-mentioned asynchronous processing method of orders is implemented.

[0020] According to a fifth aspect of an embodiment of the present disclosure, an electronic device is provided, the electronic device comprising:

[0021] a memory for storing a computer program product;

[0022] The processor is used to execute the computer program product stored in the memory, and when the computer program product is executed, the asynchronous processing method of the above order is implemented.

[0023] According to a sixth aspect of an embodiment of the present disclosure, there is provided a computer program product, comprising computer program instructions, which implement the above-mentioned asynchronous processing method of orders when executed by a processor.

[0024] Based on the above embodiments of the present disclosure, for the received order request, determine the number of tokens in the token bucket corresponding to the commodity identification information; in response to the number of tokens being not less than the purchase quantity, create a commodity order corresponding to the order request and set the order status of the commodity order to the order creation state; asynchronously process the commodity order and the inventory of the commodity; wherein the asynchronous processing of the commodity order includes persisting the order data of the commodity order, and the processing of the inventory of the commodity includes deducting the inventory of the commodity based on the purchase quantity. Thus, the technical solution of the present disclosure can intercept the order request when the number of tokens is insufficient through the token bucket, and for the order request to obtain the token, directly create the commodity order and set the order status of the commodity order to the order creation state, so that the user can know the order status in time; and the use of the token bucket helps to smoothly control the flow of order requests to avoid the impact of excessive instantaneous flow on the system; in addition, processing orders through asynchronous processing methods such as asynchronous persistence of orders and asynchronous deduction of inventory can further alleviate the load pressure of the system.

[0025] The technical solution of the present disclosure is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] By describing the embodiments of the present disclosure in more detail in conjunction with the accompanying drawings, the above and other purposes, features and advantages of the present disclosure will become more apparent. The accompanying drawings are used to provide a further understanding of the embodiments of the present disclosure and constitute a part of the specification. Together with the embodiments of the present disclosure, they are used to explain the present disclosure and do not constitute a limitation of the present disclosure. In the drawings, the same reference numerals generally represent the same components or steps.

[0027] Figure 1 A flowchart of an embodiment of the asynchronous processing method of an order disclosed in the present invention;

[0028] Figure 2 A flowchart of persistently processing order data in the asynchronous order processing method disclosed in the present invention;

[0029] Figure 3 A flow chart of batch deduction of inventory in the asynchronous order processing method disclosed in the present invention;

[0030] Figure 4 A schematic diagram of the process interaction of the asynchronous order processing method disclosed in the present invention;

[0031] Figure 5 This is a schematic diagram of the structure of an embodiment of an asynchronous order processing device disclosed in the present invention;

[0032] Figure 6 A structural diagram of another embodiment of the asynchronous order processing device disclosed in the present invention;

[0033] Figure 7 A schematic diagram of the structure of the asynchronous processing system of orders disclosed in the present invention;

[0034] Figure 8 It is a structural diagram of an electronic device provided by an exemplary embodiment of the present application. DETAILED DESCRIPTION

[0035] The exemplary embodiments according to the present disclosure will be described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, rather than all the embodiments of the present disclosure, and it should be understood that the present disclosure is not limited to the exemplary embodiments described here.

[0036] It should be noted that the relative arrangement of components and steps, the numerical expressions and numerical values ​​set forth in these embodiments do not limit the scope of the present disclosure unless specifically stated otherwise.

[0037] Those skilled in the art can understand that the terms "first" and "second" in the embodiments of the present disclosure are only used to distinguish different steps, devices or modules, etc., and neither represent any specific technical meaning nor indicate the necessary logical order between them.

[0038] It should also be understood that in the embodiments of the present disclosure, “plurality” may refer to two or more than two, and “at least one” may refer to one, two, or more than two.

[0039] It should also be understood that any component, data or structure mentioned in the embodiments of the present disclosure can generally be understood as one or more, unless explicitly limited or otherwise indicated in the context.

[0040] In addition, the term "and / or" in this disclosure is only a description of the association relationship of associated objects, indicating that there may be three relationships, such as A and / or B, which can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this disclosure generally indicates that the associated objects before and after are in an "or" relationship.

[0041] It should also be understood that the description of the various embodiments in the present disclosure focuses on the differences between the various embodiments, and the same or similar aspects thereof can be referenced to each other, and for the sake of brevity, they will not be described one by one.

[0042] At the same time, it should be understood that for the convenience of description, the sizes of the various parts shown in the drawings are not drawn according to the actual proportional relationship.

[0043] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the present disclosure, its application, or uses.

[0044] Technologies, methods, and equipment known to ordinary technicians in the relevant art may not be discussed in detail, but where appropriate, the technologies, methods, and equipment should be considered as part of the specification.

[0045] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.

[0046] The embodiments of the present disclosure can be applied to electronic devices such as terminal devices, computer systems, servers, etc., which can operate with many other general or special computing system environments or configurations. Examples of well-known terminal devices, computing systems, environments and / or configurations suitable for use with electronic devices such as terminal devices, computer systems or servers include, but are not limited to: personal computer systems, server computer systems, thin clients, thick clients, handheld or laptop devices, microprocessor-based systems, set-top boxes, programmable consumer electronics, network personal computers, small computer systems, large computer systems, and distributed cloud computing technology environments including any of the above systems, etc.

[0047] Electronic devices such as terminal devices, computer systems, servers, etc. can be described in the general context of computer system executable instructions (such as program modules) executed by computer systems. Generally, program modules can include routines, programs, target programs, components, logic, data structures, etc., which perform specific tasks or implement specific abstract data types. Computer systems / servers can be implemented in a distributed cloud computing environment. In a distributed cloud computing environment, tasks can be performed by remote processing devices linked through a communication network. In a distributed cloud computing environment, program modules can be located on local or remote computing system storage media including storage devices.

[0048] SUMMARY OF THE DISCLOSURE

[0049] In the process of realizing the present disclosure, the inventor discovered through research that when multiple people visit the platform or rush to buy a certain product at the same time, the high concurrency can easily cause a huge load pressure on the server of the e-commerce platform, and users are unable to perceive the order status in time.

[0050] In the asynchronous processing method of orders provided by the technical solution of the present disclosure, after receiving the order request sent by the client, the number of tokens in the token bucket corresponding to the commodity identification information can be obtained; and when the number of tokens is not less than the purchase quantity purchased by the user, the commodity order corresponding to the order request is created and the order status of the commodity order is set to the order creation status; and then the orders are processed asynchronously in batches. Therefore, the technical solution of the present disclosure can not only generate order data in a timely manner so that the user can be informed of the order status in a timely manner when querying the order status, but also help to relieve the load pressure of the server by asynchronously processing orders.

[0051] Exemplary Methods

[0052] Figure 1 FIG. 1 is a flow chart of an embodiment of the asynchronous processing method of an order disclosed in the present invention. Figure 1 The method shown includes steps 101 to 104. Each step is described below.

[0053] In step 101, an order request sent by a client is received, wherein the order request carries the commodity identification information and the purchase quantity of the requested commodity.

[0054] The commodity identification information is used to uniquely identify the commodity purchased in the order request. The commodity identification information can be a combination of numbers or letters. The server can accurately identify the specific commodity based on the commodity identification information and obtain the inventory of the commodity corresponding to the commodity identification information from the inventory database. The purchase quantity is used to indicate the quantity of the commodity requested to be purchased in the order request.

[0055] In step 102, the number of tokens in the token bucket corresponding to the commodity identification information is determined.

[0056] Among them, there is a non-strong consistency between the number of tokens in the token bucket corresponding to the product identification information and the inventory quantity corresponding to the product identification information.

[0057] In this embodiment, one product identification information corresponds to one token bucket, and the token bucket corresponding to each product has a short life cycle. When a user accesses a product, he can first query whether there is a token bucket corresponding to the product identification information of the product. If there is no corresponding token bucket, a token bucket is created and filled with tokens consistent with the inventory corresponding to the product identification information, so that the number of tokens is consistent with the inventory when the token bucket is created; when no one accesses the product corresponding to the token bucket or the life cycle of the token bucket ends, the token bucket can be automatically released to avoid waste of resources, and there is no need to consume computing resources to continuously maintain the consistency of the number of tokens and the inventory.

[0058] In this example, redis is used to execute the Lua script command to query the number of tokens in the token bucket corresponding to the product identification information, and determine whether the number of tokens is less than the purchase quantity based on the incoming purchase quantity. If the number of tokens is not less than the purchase quantity, step 103 is executed to create an order and perform subsequent asynchronous processing operations; if the number of tokens is less than the purchase quantity, a notification message of failed purchase is returned to the client to promptly inform the user when the purchase fails.

[0059] Among them, the redis command has sequentiality and high availability, and the execution of the lua script is also single-threaded, so the sequentiality of the token bucket obtaining tokens is met, and the sequentiality of order request processing can be achieved.

[0060] In step 103, in response to the token quantity being not less than the purchase quantity, a commodity order corresponding to the order request is created and the order status of the commodity order is set to an order creating status.

[0061] The operation of creating a product order corresponding to the order request at least includes: generating order data, storing the order data and order status of the product order in a cache, and sending the order number of the product order to the client.

[0062] Among them, the order data includes order number, product information (including product identification information, product name, specifications), purchase quantity, order time, customer information, etc. The order number is used to uniquely identify an order.

[0063] In this embodiment, the order status is used to indicate the various states after receiving the order request and executing the order creation operation, including: order creation status, payment pending status, shipment pending status, shipped status, receipt pending status, and transaction completion status. Among them, the order creation status is used to indicate that the above order data has been generated, but the inventory has not yet been deducted; when the asynchronous inventory deduction is successful, the order status is updated from the creation status to the payment pending (payment pending) status; after the user pays successfully, the order status is updated from the payment pending (payment pending) status to the shipment pending status; after the merchant ships the goods, the order status is updated from the shipment pending status to the receipt pending status; when the user receives the goods and confirms that the order is completed, the order status is updated from the receipt pending status to the transaction completion status.

[0064] In this embodiment, the order creation operation and the inventory deduction operation are separated through the "order creation status". After executing the order creation operation, the system sets the order status to "order creation status", thereby providing support for asynchronous execution of inventory deduction operations, helping to alleviate system load pressure, and at the same time improving the fault tolerance and simplicity of order data that fails to be intercepted by the token bucket.

[0065] In this embodiment, the specific operations of generating order data may include: generating an order number (such as orderAid), creating order data (including product information (including product identification information, product name, specifications), purchase quantity, order time, customer information, etc.), etc.

[0066] In this embodiment, after storing the order data and order status of the commodity order in the cache, it is helpful to directly read the order data and order status from the cache and feedback to the user when the user queries the order information through the client. In specific implementation, the order data can be stored in a hash table, with the order number of the order as the key and other order data as the value, so as to store the order data in the form of key-value pairs.

[0067] It is understandable that when the order data is generated, returning the order number information to the client helps the user to obtain the order status through the order number in a timely manner.

[0068] In step 104, the product order and the inventory of the product are processed asynchronously; wherein the asynchronous processing of the product order includes: persisting the order data of the product order, and the processing of the inventory of the product includes: deducting the inventory of the product based on the purchase quantity.

[0069] In this embodiment, asynchronous processing refers to decomposing the order processing process into multiple steps such as generating order data, persisting orders, and inventory deductions, and distributing these steps to different processing units for parallel processing. This implementation method helps to improve the overall efficiency and stability of the system.

[0070] In some implementations, the commodity orders to be asynchronously processed can be processed through message queues to implement asynchronous persistence processing of order data and asynchronous inventory deduction processing by different processing units. For specific implementation methods, see Figure 2 and Figure 4 The illustrated embodiment will not be described in detail here.

[0071] In other implementations, a multi-thread or multi-process approach may be used to implement asynchronous persistence of order data and asynchronous inventory deduction through different processes. For example, process 1 is used to create an order, process 2 is used to perform asynchronous persistence of order data, and process 3 is used to implement asynchronous inventory deduction of an order.

[0072] In other embodiments, the asynchronous persistence processing and asynchronous inventory deduction processing of order data can also be implemented by means of an asynchronous task framework. For example, through the Swoole framework (the Swoole framework is an asynchronous network communication framework that provides multiple functions such as coroutines, multi-processes, and Transmission Control Protocol (TCP) / User Datagram Protocol (UDP) are two different network transmission protocols, and supports asynchronous concurrent processing), the asynchronous persistence processing logic and asynchronous inventory deduction processing logic of order data are respectively encapsulated as asynchronous tasks and processed in parallel with order creation.

[0073] Through the above steps 101-104, for the received order request, the number of tokens in the token bucket corresponding to the commodity identification information is determined; in response to the number of tokens being not less than the purchase quantity, a commodity order corresponding to the order request is created and the order status of the commodity order is set to the order creation state; the commodity order and the inventory of the commodity are processed asynchronously; wherein the asynchronous processing of the commodity order includes persisting the order data of the commodity order, and the processing of the inventory of the commodity includes deducting the inventory of the commodity based on the purchase quantity. Thus, the technical solution disclosed in the present invention can intercept the order request when the number of tokens is insufficient through the token bucket, and for the order request to obtain the token, the commodity order is directly created and the order status of the commodity order is set to the order creation state, so that the user can know the order status in time; and the use of the token bucket helps to smoothly control the flow of order requests to avoid the impact of excessive instantaneous flow on the system; in addition, processing orders through asynchronous processing methods such as asynchronous persistence of orders and asynchronous deduction of inventory can further alleviate the load pressure of the system.

[0074] In some optional implementations, in response to receiving a query request sent by a client, the order number of the order to be viewed is obtained from the query request; the order data corresponding to the order number is queried in the cache; in response to the query result indicating that there is no order data corresponding to the order number in the cache, the order data corresponding to the order number is read from the order database and stored in the cache; in response to the query result indicating that there is order data corresponding to the order number in the cache, the order data corresponding to the order number is returned to the client.

[0075] In this implementation, after creating an order and sending the order number to the client, the user can send a query request to view the order data through the client. The server can query the order data corresponding to the order number in the cache according to the order number in the query request. If there is order data corresponding to the order number in the cache, the order data corresponding to the order number can be directly returned to the client; if there is no order data corresponding to the order number in the cache, the order data corresponding to the order number is read from the order database and stored in the cache. Among them, the order database is the database where the order data is written when the order data is persisted.

[0076] Figure 2 Flow chart of persistent processing of order data in the asynchronous processing method of order disclosed in the present invention. The present invention takes how to asynchronously persist order data as an example for illustrative description. Figure 2 The method shown includes step 201 to step 202. Each step is described below.

[0077] In step 201, a persistent order message is pushed to a first message queue. The first message queue stores at least one persistent order message. Each persistent order message carries order data of one product order in at least one product order.

[0078] In this embodiment, in the event of product promotion, flash sales and other activities, at least one order request for a product sent by at least one client will be received within a short period of time. Figure 1 In the illustrated embodiment, after creating an order for each order request, at least one persistent order message may be pushed to the first message queue, and each persistent order message carries order data of a commodity order to be persisted.

[0079] The first message queue is a queue for the order creation unit to transmit messages to the persistent order unit. After creating a product order, the order creation unit can push a persistent order message carrying the order data of the product order to the first message queue.

[0080] Exemplarily, after order orderA is created, persistent order data of orderA may be inserted into the first message queue, and the order data includes the order number (such as orderAid), product identification information, product name, specifications, purchase quantity, order time, customer information, etc.

[0081] It is understandable that when a large amount of order data is generated at the same time or within a very short time interval, a large amount of order data to be persisted may be inserted into the first message queue within the very short time interval.

[0082] In step 202, batch persistence processing is performed on the order data carried by at least one persistent order message in the first message queue. The batch persistence processing is to write at least one order data into the order database in batches.

[0083] The persistent order processing unit may pull messages from the first message queue according to set rules and perform batch persistent processing. The set rules may include: a maximum number of messages pulled each time and a time for pulling messages each time.

[0084] Exemplarily, the preset rule for pulling messages from the first message queue may be to pull a maximum of 100 order data each time, and the time for pulling messages each time is to pull a new order after processing the last pulled order.

[0085] In this embodiment, order data is persisted in batches, which means that order data is inserted into a database in batches. By inserting order data into a database, for example, inserting order data of order A, order B, order C, order D, and order E in batches through one SQL statement, it helps to reduce the number of database requests, thereby improving insertion efficiency and reducing system pressure and resource consumption.

[0086] Through the above steps 201-202, the implementation method of persistent processing of order data is disclosed. By pushing the persistent message carrying the order data to the first message queue, the asynchronous processing of the persistent order can be realized; and by writing the order data in batches to the order database, it helps to reduce the number of database requests, thereby improving the insertion efficiency and reducing the system pressure and resource consumption.

[0087] Figure 3 The flowchart of batch deduction of inventory in the asynchronous processing method of the order disclosed in the present invention is as follows. The embodiment of the present invention takes how to asynchronously deduct inventory as an example for illustrative description. Figure 3 The method shown includes step 301 to step 303. Each step is described below.

[0088] In step 301, in response to completion of persistence processing of at least one order data, an inventory deduction message is pushed to a second message queue, in which at least one inventory deduction message is stored, each inventory deduction message carrying order data of one of at least one commodity order.

[0089] The second message queue is a queue used by the persistent order unit to transmit messages to the inventory deduction unit. After the persistent order unit processes the order data persistently, it can push an inventory deduction message for deducting inventory to the second message queue. The inventory deduction message carries at least the order number, product identification information, and purchase quantity of the inventory to be deducted.

[0090] Exemplarily, after orderA is persisted, the order number orderAid, product identification information (product A), and purchase quantity (for example, the purchase quantity is 3) of orderA may be inserted into the second message queue.

[0091] In step 302, based on the purchase quantity in the order data carried by at least one inventory deduction message, the total purchase amount of the commodity corresponding to the at least one order request is determined.

[0092] The inventory deduction unit may pull the inventory deduction message from the second message queue according to a preset rule, and the preset rule may include: a maximum number of messages pulled each time and a time for pulling each message.

[0093] Exemplarily, the preset rule for pulling messages from the second message queue may be to pull a maximum of 100 order data each time, and the time for pulling messages each time is to pull a new order after processing the last pulled order.

[0094] Among them, the order data of the commodity orders is processed for inventory deduction in a batch deduction manner, which means that the number of commodities in multiple orders for purchasing the same commodity is summed up, and then the inventory is deducted at one time. For example, the total SUM1 of commodity a purchased by order A, order B, order C, order D, and order E is calculated, and then the number SUM is subtracted from the commodity inventory at one time.

[0095] In step 303, a one-time inventory deduction operation is performed based on the total purchase amount of the goods.

[0096] In some embodiments, if the value of the sum SUM1 of the purchased goods a of the orders to be deducted from the inventory is greater than the total inventory number m, it means that the inventory is insufficient, and the orders to be deducted from the inventory can be sorted according to the creation time of each order, and the inventory deduction operation is performed on the orders with earlier creation time in accordance with the principle of first deducting the inventory of the orders created first. For example, if the sum SUM1 of the purchased goods a of orders A, B, C, D, and E sorted by creation time is greater than the total inventory number m, and the sum SUM2 of the purchased goods a of orders A, B, C, and D is not greater than the total inventory number m, then only the inventory of orders A, B, C, and D can be deducted, and the inventory of order E cannot be deducted, that is, the inventory deduction of orders A, B, C, and D is successful, and the inventory deduction of order E fails.

[0097] In some embodiments, if the token bucket lifecycle of a product ends but the asynchronous inventory persistence process is not completed, that is, the inventory deduction of some orders has not been completed, if a new order request is received at this time, the token bucket will be recreated and the expired inventory (the inventory is the amount of inventory that has not yet been deducted for some orders) will be synchronized, resulting in the number of tokens in the token bucket being greater than the actual available inventory, which will cause the inventory deduction of some orders created subsequently to fail.

[0098] Through the above steps 301 to 303, the implementation method of inventory deduction is disclosed. By inserting the order for inventory to be deducted into the second message queue, asynchronous processing of inventory deduction can be achieved; and by performing a one-time inventory deduction operation based on the sum of purchase quantities corresponding to multiple inventory deduction messages, it helps to reduce the number of requests to the inventory database, thereby improving inventory deduction efficiency and reducing system pressure and resource consumption.

[0099] In some optional implementations, after a deduction operation is performed on the inventory, the order status of the product order in the cache and the order status in the order database are updated accordingly based on the inventory deduction status, and the inventory deduction status is used to indicate the operation status of the inventory deduction operation; and, in response to the inventory deduction status being a successful deduction, an order payment notification message is sent to the client; in response to the inventory deduction status being a failed deduction, a notification message of order inventory deduction failure is sent to the client.

[0100] In this implementation, for product orders from which inventory deductions are successful, the order status of the product order in the cache and the order status in the order database can be updated to a pending payment status, and an order payment notification message can be sent to the client to remind the user to promptly perform the payment operation and complete the order. For product orders from which inventory deductions fail, the order status of the product order in the cache and the order status in the order database can be updated to an inventory deduction status, and a notification message of failed order inventory deduction can be sent to the client to remind the user that the order creation failed and the product purchase failed.

[0101] Figure 4 The figure is a flow diagram of the asynchronous processing method of the order disclosed in the present invention. The embodiment of the present invention takes the example of the asynchronous processing of the order realized by the interaction of various units (order creation and cache unit, persistent order unit, inventory deduction unit) as an example. Figure 4 The method shown includes steps 401 to 415. Each step is described below.

[0102] In step 401, an order request sent by a client is received.

[0103] The order request carries product identification information and purchase quantity.

[0104] The specific implementation of step 401 can be found in Figure 1 The description of step 101 of the illustrated embodiment is not described in detail here.

[0105] In step 402, it is determined whether there is a token bucket corresponding to the above commodity identification information.

[0106] In this example, redis is used to execute a Lua script command to query whether there is a token bucket corresponding to the product identification information in the redis cache. If there is no token bucket corresponding to the product identification information in the cache, step 403 is executed. If there is a token bucket corresponding to the product identification information in the cache, step 406 can be executed.

[0107] In step 403, a token bucket corresponding to the commodity identification information is created, the inventory quantity corresponding to the commodity identification information is obtained, and the token bucket is filled with tokens that are consistent with the inventory quantity.

[0108] In this embodiment, the token bucket corresponding to each commodity has a short life cycle. When no one accesses the commodity corresponding to the token bucket or the life cycle of the token bucket ends, the token bucket can be automatically released to avoid waste of resources. Therefore, when a user accesses a commodity, it can first check whether there is a token bucket corresponding to the commodity identification information of the commodity. If there is no corresponding token bucket, a token bucket can be created and filled with tokens consistent with the inventory number corresponding to the commodity identification information, so that the number of tokens is consistent with the inventory when the token bucket is created.

[0109] In step 404, the number of tokens in the token bucket corresponding to the commodity identification information is determined.

[0110] The specific implementation of step 404 can be found in Figure 1 The description of step 102 of the illustrated embodiment will not be described in detail here.

[0111] Further, in response to the number of tokens being less than the purchase number, step 405 is executed; in response to the number of tokens being not less than the purchase number, step 406 is executed.

[0112] In step 405, in response to the token quantity being less than the purchase quantity, a notification message of purchase failure is returned to the client.

[0113] In step 406, in response to the token quantity being not less than the purchase quantity, an operation of creating a commodity order corresponding to the order request is executed.

[0114] The operation at least includes: generating order data, setting the order status to a creating status, storing the order data and order status of the product order in a cache, and sending the order number of the product order to the client.

[0115] The specific implementation of step 406 can be found in Figure 1 The description of step 103 of the illustrated embodiment will not be described in detail here.

[0116] In step 407, a persistent order message containing order data of a persistent commodity order is pushed to the first message queue.

[0117] In step 408, at least one persistent order message is read.

[0118] In step 409, batch persistence processing is performed on at least one order data carried in at least one persistent order message in the first message queue.

[0119] The batch persistence processing is to write the order data of at least one commodity order into the order database in batches.

[0120] The specific implementation of steps 407 to 409 can be found in Figure 2The illustrated embodiment will not be described in detail here. In response to the order data of at least one commodity order being persisted, step 410 is executed.

[0121] In step 410, a stock deduction message for deducting stock is pushed to the second message queue.

[0122] In step 411, at least one inventory reduction message is read.

[0123] In step 412, based on the total purchase quantity corresponding to at least one inventory deduction message, a one-time inventory deduction operation is performed to achieve batch inventory deduction.

[0124] The specific implementation of steps 410 to 412 can be found in Figure 3 The illustrated embodiment will not be described in detail here.

[0125] Further, according to the inventory deduction result, step 413 and step 415 are respectively executed.

[0126] In step 413, based on the inventory deduction status, the order status of the commodity order in the cache and the order status in the order database are updated accordingly.

[0127] In step 414, an order payment notification message is sent to the client.

[0128] In this implementation, for product orders with successful inventory deductions, the order status of the product order in the cache and the order status in the order database can be updated to a pending payment status. By sending an order payment notification message to the client, the user can be reminded to perform the payment operation in a timely manner to complete the order.

[0129] In step 415, a notification message of order inventory deduction failure is sent to the client.

[0130] In this implementation, for product orders that fail to have inventory deductions, the order status of the product order in the cache and the order status in the order database can be updated to the inventory deduction status. By sending a notification message of failed order inventory deductions to the client, the user can be reminded that the order creation failed and the product purchase failed.

[0131] In the disclosed embodiment, a method for implementing asynchronous processing of orders by different processing units in the server (which may be located in different service nodes or on the same service node) through interaction is disclosed. In the disclosed technical solution, the number of tokens in the token bucket does not need to be strongly consistent with the inventory, and resources are automatically released during the life cycle, which can meet high fault tolerance and reduce maintenance and development costs; and from the business level, in conjunction with the "Creating" and "Inventory Allocation Failed" orders, the final consistency of tokens and inventory can be achieved, and the scenario of selling less or more will not occur.

[0132] Exemplary Devices

[0133] Figure 5 FIG. 1 is a schematic diagram of the structure of an embodiment of an asynchronous order processing device disclosed in the present invention. Figure 5 As shown, the device comprises:

[0134] The first receiving module 51 is used to receive an order request sent by a client, wherein the order request carries the commodity identification information and the purchase quantity of the requested commodity;

[0135] A first determination module 52, used to determine the number of tokens in the token bucket corresponding to the commodity identification information;

[0136] An order creation module 53, configured to create a commodity order corresponding to the order request and set the order status of the commodity order to an order creation status in response to the token quantity being not less than the purchase quantity;

[0137] The asynchronous processing module 54 is used to asynchronously process the commodity order and the inventory of the commodity; wherein the asynchronous processing of the commodity order includes: persisting the order data of the commodity order, and processing the inventory of the commodity includes: deducting the inventory of the commodity based on the purchase quantity.

[0138] Figure 6 A schematic diagram of the structure of another embodiment of the asynchronous processing device for orders disclosed in the present invention. Figure 6 As shown, in Figure 5 On the basis of the illustrated embodiment, in some implementations of the present disclosure, the first receiving module 51 is used to receive at least one order request for a product sent by at least one client;

[0139] The asynchronous processing module 54 includes:

[0140] The first push submodule 541 is used to push a persistent order message to the first message queue, in which at least one persistent order message is stored, and each persistent order message carries order data of one product order in at least one product order;

[0141] The first processing submodule 542 is used to perform batch persistence processing on the order data carried by at least one persistent order message in the first message queue. The batch persistence processing is to write at least one order data into the order database in batches.

[0142] In some embodiments of the present disclosure, the device further comprises:

[0143] The acquisition module 55 is used to obtain the order number of the order to be viewed from the query request in response to receiving the query request sent by the client;

[0144] A query module 56, used to query the order data corresponding to the order number in the cache;

[0145] A loading module 57, configured to read the order data corresponding to the order number from the order database and store it in the cache in response to the query result indicating that there is no order data corresponding to the order number in the cache;

[0146] The first sending module 58 is configured to return the order data corresponding to the order number to the client in response to the query result indicating that there is order data corresponding to the order number in the cache.

[0147] In some embodiments of the present disclosure, the asynchronous processing module 54 includes:

[0148] The second push submodule 543 is configured to push a stock deduction message to a second message queue in response to completion of persistence processing of at least one order data, wherein the second message queue stores at least one stock deduction message, and each stock deduction message carries order data of one product order in at least one product order;

[0149] A summing submodule 544 is used to determine the total purchase amount of the commodity corresponding to the at least one order request based on the purchase quantity in the order data carried by the at least one inventory deduction message;

[0150] The second processing submodule 545 is used to perform a one-time inventory deduction operation based on the total purchase amount of the goods.

[0151] In some embodiments of the present disclosure, the device further comprises:

[0152] A first updating module 59, configured to update the order status of the commodity order in the cache and the order status in the order database accordingly based on the inventory deduction status, wherein the inventory deduction status is used to indicate the operation status of the inventory deduction operation;

[0153] The second sending module 60 is used to send an order payment notification message to the client in response to the inventory deduction status being a successful deduction.

[0154] The third sending module 61 is used for sending a notification message of order inventory deduction failure to the client in response to the inventory deduction status being deduction failure.

[0155] In some embodiments of the present disclosure, the device further comprises:

[0156] A token bucket creation module 62, configured to create a token bucket corresponding to the commodity identification information in response to the absence of a token bucket corresponding to the commodity identification information;

[0157] Inventory module 63, used to obtain the inventory quantity corresponding to the commodity identification information;

[0158] The token filling module 64 is used to fill the token bucket with a number of tokens that is consistent with the inventory.

[0159] In some embodiments of the present disclosure, the device further includes: a fourth sending module 65, configured to return a notification message of purchase failure to the client in response to the number of tokens being less than the purchase number.

[0160] The device of the embodiment of the present disclosure can be used to implement the methods of the above-mentioned embodiments of the present disclosure. The two correspond to each other in specific implementation, and the specific implementations of related parts are referenced to each other, which will not be repeated here.

[0161] Exemplary systems, electronic devices, computer program products, and computer-readable storage media

[0162] The disclosed embodiment also provides an asynchronous processing system for orders, such as Figure 7 As shown, the system includes an order creation unit 71, a persistent order unit 72, and an inventory deduction unit 73; wherein,

[0163] The order creation unit 71 is used to receive an order request sent by a client, the order request carrying the commodity identification information and the purchase quantity of the requested commodity; determine the number of tokens in the token bucket corresponding to the commodity identification information; in response to the number of tokens being not less than the purchase quantity, create a commodity order corresponding to the order request and set the order state of the commodity order to the order creation state; push a persistent order message to the first message queue, the first message queue stores at least one persistent order message, and each persistent order message carries the order data of a commodity order;

[0164] The persistent order unit 72 is used to perform batch persistent processing on at least one order data in at least one persistent order message in the first message queue, and the batch persistent processing is to write at least one order data in batches into the order database; after completing the batch persistent processing of the order, push the inventory deduction message to the second message queue, and the second message queue stores at least one inventory deduction message, and each inventory deduction message carries the order data of a commodity order;

[0165] The inventory deduction unit 73 is used to determine the total purchase amount of goods corresponding to at least one order request based on the purchase quantity in the order data carried by at least one inventory deduction message; and perform a one-time inventory deduction operation based on the total purchase amount of goods.

[0166] An embodiment of the present disclosure further provides an electronic device, comprising: a memory for storing a computer program; a processor for executing the computer program stored in the memory, and when the computer program is executed, the asynchronous processing method of an order of any of the above embodiments of the present disclosure is implemented.

[0167] Below, reference Figure 8 An electronic device according to an embodiment of the present disclosure is described, in which a device for implementing the method according to an embodiment of the present disclosure may be integrated. Figure 8 A structural diagram of an electronic device provided in an exemplary embodiment of the present disclosure, such as Figure 8 As shown, the electronic device includes one or more processors 81, one or more computer-readable storage media memory 82, and a computer program stored in the memory and executable on the processor. When executing the program in the memory 82, the above-mentioned asynchronous processing method of the order can be implemented.

[0168] Specifically, in practical applications, the electronic device may further include components such as an input device 83 and an output device 84, and these components are interconnected via a bus system and / or other forms of connection mechanisms (not shown). Those skilled in the art will appreciate that Figure 8 The structure of the electronic device shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure, or certain components, or different component arrangements.

[0169] The processor 81 can be a central processing unit (CPU) or other forms of processing units with ordered asynchronous processing capabilities and / or instruction execution capabilities. It performs various functions and processes data by running or executing software programs and / or modules stored in the memory 82, and calling data stored in the memory 82, thereby monitoring the electronic device as a whole.

[0170] The memory 82 may store one or more computer program products, and the memory may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The above-mentioned volatile memory may include, for example, random access memory (RAM) and / or cache memory (cache), etc. The above-mentioned non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, etc. One or more computer program products may be stored on the computer-readable storage medium, and the processor 81 may run the computer program products to implement the asynchronous processing method of the order of each embodiment of the present disclosure and / or other desired functions.

[0171] The input device 83 can be used to receive input digital or character information. The input device 83 can include a keyboard, a mouse, a joystick, etc. related to user settings and function control.

[0172] The output device 84 can output various information to the outside, including the determined distance information, direction information, etc. The output device 84 can include, for example, a display, a speaker, a printer, a communication network and a remote output device connected thereto, and the like.

[0173] The electronic device may also include a power supply for supplying power to various components, which may be logically connected to the processor 81 through a power management system, so as to manage charging, discharging, power consumption and other functions through the power management system. The power supply may also include one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, power status indicators and other arbitrary components.

[0174] Of course, to simplify, Figure 8 Only some of the components related to the present disclosure in the electronic device are shown, and components such as a bus, an input / output interface, etc. are omitted. In addition, according to specific application situations, the electronic device may further include any other appropriate components.

[0175] In addition to the above-mentioned methods and devices, an embodiment of the present disclosure may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps of the asynchronous processing method of orders according to various embodiments of the present disclosure described in the above-mentioned "Exemplary Method" section of this specification.

[0176] The computer program product may be written in any combination of one or more programming languages ​​to write program code for performing the operations of the disclosed embodiments, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0177] In addition, an embodiment of the present disclosure may also be a computer-readable storage medium having computer program instructions stored thereon, which, when executed by a processor, causes the processor to execute the steps of the asynchronous processing method of orders according to various embodiments of the present disclosure described in the above “Exemplary Method” section of this specification.

[0178] Computer readable storage media can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can include, for example, but is not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0179] The basic principles of the present disclosure are described above in conjunction with specific embodiments. However, it should be noted that the advantages, strengths, effects, etc. mentioned in the present disclosure are only examples and not limitations, and it cannot be considered that these advantages, strengths, effects, etc. are required by each embodiment of the present disclosure. In addition, the specific details disclosed above are only for the purpose of illustration and ease of understanding, and are not limitations. The above details do not limit the present disclosure to the necessity of adopting the above specific details to be implemented.

[0180] Each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the system embodiment, since it basically corresponds to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0181] A person of ordinary skill in the art can understand that all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk, etc., various media that can store program codes.

[0182] The method and apparatus of the present disclosure may be implemented in many ways. For example, the method and apparatus of the present disclosure may be implemented by software, hardware, firmware, or any combination of software, hardware, and firmware. The above order of steps for the method is for illustration only, and the steps of the method of the present disclosure are not limited to the order specifically described above, unless otherwise specifically stated. In addition, in some embodiments, the present disclosure may also be implemented as a program recorded in a recording medium, which includes machine-readable instructions for implementing the method according to the present disclosure. Therefore, the present disclosure also covers a recording medium storing a program for executing the method according to the present disclosure.

[0183] The description of the present disclosure is given for the purpose of illustration and description, and is not intended to be exhaustive or to limit the present disclosure to the disclosed form. Many modifications and variations will be apparent to those of ordinary skill in the art. The embodiments are selected and described in order to better illustrate the principles and practical applications of the present disclosure, and to enable those of ordinary skill in the art to understand the present disclosure and thereby design various embodiments with various modifications suitable for specific uses.

Claims

1. An asynchronous processing method for an order, characterized in that: include: Receive an order request sent by a client, wherein the order request carries the commodity identification information and the purchase quantity of the requested commodity; Determine the number of tokens in the token bucket corresponding to the commodity identification information; In response to the token quantity being not less than the purchase quantity, creating a commodity order corresponding to the order request and setting the order status of the commodity order to an order creating status; Asynchronously processing the commodity order and the inventory of the commodity; wherein the asynchronous processing of the commodity order includes: persisting the order data of the commodity order, and processing the inventory of the commodity includes: deducting the inventory of the commodity based on the purchase quantity.

2. The method according to claim 1, characterized in that: The receiving an order request sent by a client includes: receiving at least one order request sent by at least one client for the commodity; For at least one commodity order created by the at least one order request, the persistent processing of the order data of the commodity order includes: Pushing a persistent order message to a first message queue, wherein the first message queue stores at least one persistent order message, each of the persistent order messages carrying order data of one of the at least one product order; The order data carried by at least one persistent order message in the first message queue is subjected to batch persistence processing, wherein the batch persistence processing is to write the at least one order data into an order database in batches.

3. The method according to claim 2, characterized in that The method further comprises: In response to receiving a query request sent by a client, obtaining an order number of the order to be queried from the query request; Query the cache for order data corresponding to the order number; In response to the query result indicating that there is no order data corresponding to the order number in the cache, reading the order data corresponding to the order number from the order database and storing it in the cache; In response to the query result indicating that the cache contains order data corresponding to the order number, the order data corresponding to the order number is returned to the client.

4. The method according to claim 2, characterized in that: The deduction process of the inventory of the commodity based on the purchase quantity includes: In response to completion of persistence processing of at least one order data, pushing a stock deduction message to a second message queue, wherein the second message queue stores at least one stock deduction message, each of the stock deduction messages carrying order data of one of the at least one commodity order; Determining a total purchase amount of the commodity corresponding to the at least one order request based on a purchase quantity in the order data carried by the at least one inventory deduction message; Based on the total purchase amount of the goods, a one-time inventory deduction operation is performed.

5. The method according to claim 4, characterized in that After performing a one-time inventory deduction operation based on the total purchase quantity, the method further includes: Based on the inventory deduction status, correspondingly updating the order status of the commodity order in the cache and the order status in the order database, wherein the inventory deduction status is used to indicate the operation status of the inventory deduction operation; and In response to the inventory deduction status being a successful deduction, sending an order payment notification message to the client; In response to the inventory deduction status being deduction failure, a notification message of order inventory deduction failure is sent to the client.

6. The method according to any one of claims 1 to 5, characterized in that: After receiving the order request sent by the client, the method further includes: In response to the token bucket corresponding to the commodity identification information not existing, creating a token bucket corresponding to the commodity identification information; Obtaining the inventory quantity corresponding to the commodity identification information; The token bucket is filled with a number of tokens that is consistent with the inventory quantity of the commodity.

7. The method according to any one of claims 1 to 6, characterized in that: In response to the number of tokens being less than the purchase number, the method further includes: A notification message of purchase failure is returned to the client.

8. An asynchronous order processing system, characterized in that: The system includes: an order creation unit, a persistent order unit, and an inventory deduction unit; The order creation unit is used to receive an order request sent by a client, wherein the order request carries the commodity identification information and the purchase quantity of the requested commodity; determine the number of tokens in the token bucket corresponding to the commodity identification information; in response to the number of tokens being not less than the purchase quantity, create a commodity order corresponding to the order request and set the order state of the commodity order to the order creation state; push a persistent order message to a first message queue, wherein the first message queue stores at least one persistent order message, and each of the persistent order messages carries the order data of a commodity order; The persistent order unit is used to perform batch persistence processing on at least one order data in at least one persistent order message in the first message queue, wherein the batch persistence processing is to write the at least one order data in batches into the order database; after completing the batch persistence processing of the order, push the inventory deduction message to the second message queue, wherein the second message queue stores at least one inventory deduction message, and each inventory deduction message carries the order data of a commodity order; The inventory deduction unit is used to determine the total purchase amount of goods corresponding to the at least one order request based on the purchase quantity in the order data carried by at least one inventory deduction message; and perform a one-time inventory deduction operation based on the total purchase amount of goods.

9. A computer-readable storage medium, wherein the storage medium stores computer program instructions, and when the computer program instructions are executed, the method according to any one of claims 1 to 7 is implemented.

10. An electronic device, comprising: a memory for storing a computer program product; A processor is used to execute the computer program product stored in the memory, and when the computer program product is executed, it implements the method described in any one of claims 1 to 7.

11. A computer program product comprising computer program instructions, characterized in that When the computer program instructions are executed by a processor, the method described in any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Application of short-time high-concurrency rush-to-purchase scenario

    CN107609924A

  • Message persistence processing method and device and storage medium

    CN111770030A

  • High-concurrency service scene processing method and system and storage medium

    CN113887935A

  • Trade order asynchronous processing method

    CN115330478A

  • Asynchronous scheduling method, system, device, equipment and medium

    CN115720156A