High-concurrency inventory cancel-after-verification method
By adopting distributed locking, optimistic locking, pre-withdrawal and asynchronous processing technologies in high-concurrency inventory management systems, the shortcomings of traditional systems in high-concurrency scenarios are solved, the efficiency and consistency of inventory operations are achieved, and the user experience and system stability are improved.
Patent Information
- Application Number
- CN202411768054.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-04
- Publication Date
- 2025-03-21
AI Technical Summary
In high concurrency scenarios, traditional inventory management systems are prone to problems such as over-issuance of inventory and data out of synchronization, which harms player experience and affects brand reputation and economic benefits.
We adopt distributed locking, optimistic locking mechanism, pre-stocking and asynchronous processing methods to ensure the efficiency and consistency of inventory operations. The specific steps include: locking the inventory items in the distributed lock stage, adding the version number to the inventory record in the optimistic lock stage, subtracting the corresponding quantity when the user submits an order, and completing payment within the valid period, and asynchronous processing stage performs inventory updates and order confirmation asynchronously through the message queue.
It improves the system's processing capability in high concurrency situations, avoids inventory oversold, ensures the accuracy and consistency of inventory data, optimizes the user experience, and improves the stability of the system.
Smart Images

Figure CN119669243A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data entertainment technology, and in particular to a high-concurrency inventory write-off method. Background Art
[0002] With the rapid development of the digital entertainment industry, especially in the field of game distribution, game companies often face a large number of user participation requests in a short period of time when holding large-scale online events or releasing new games, which creates great high-concurrency pressure on the background system. Especially in activities such as the distribution, exchange, and lottery of virtual items in games, traditional inventory management systems are prone to problems such as over-inventory and data asynchrony when dealing with such instantaneous peak traffic, which not only damages the players' gaming experience, but also seriously affects the company's brand reputation and economic benefits. Therefore, developing an efficient and reliable inventory write-off solution for high-concurrency scenarios is crucial to improving the operational efficiency and user satisfaction of game distribution activities.
[0003] Existing technologies have the following defects and deficiencies in handling high-concurrency inventory management, especially in game distribution and digital entertainment scenarios: 1. Insufficient concurrency control; 2. Data consistency issues; 3. Insufficient monitoring and early warning mechanisms. Summary of the invention
[0004] In view of the above problems, a high-concurrency inventory write-off method is now provided to solve the problems existing in the prior art.
[0005] The specific technical solutions are as follows: A high-concurrency inventory write-off method, the method comprising the following steps: S1, distributed lock phase, locks the inventory items to be modified; S2, optimistic locking stage, add a version number to the inventory record. Every time the inventory is updated, not only the inventory quantity needs to be updated, but also the version number needs to be checked to see if it is consistent with the one read; S3, withholding inventory stage: when the user submits an order or redemption request, the corresponding quantity is immediately deducted from the withholding inventory, the actual inventory is maintained, and the validity period of the withholding inventory is set. For orders that have not been paid for after the validity period, the withholding inventory is released; S4, asynchronous processing stage, the operations of inventory update and order confirmation are executed asynchronously through the message queue, and the front end immediately sends a response message to the customer until the processing is completed and the actual inventory is deducted.
[0006] The above-mentioned high-concurrency inventory write-off method also has the following characteristics: step S1 includes the following steps: S11, user request processing, when a user initiates a purchase request or redemption request, the system distributes it to an available server node through a load balancer; S12: Distributed lock acquisition: the server node attempts to obtain the inventory operation lock of the product from the distributed lock service; S13. Determine whether the operation lock is occupied. If so, the request enters a queue or prompts the user to try again later. If not, proceed to step S2.
[0007] The above-mentioned high-concurrency inventory write-off method also has the following characteristics: step S2 comprises the following steps: S21, optimistic lock check, after successfully acquiring the operation lock, the server node reads the current inventory and version number of the product from the database; S22, read the current inventory and version number of the product; S23. Determine whether the read version number is consistent with the latest version number in the database. If so, proceed to step S3. If not, a concurrency conflict occurs, prompting the user to resubmit the request.
[0008] The above-mentioned high-concurrency inventory write-off method also has the following characteristics: step S3 comprises the following steps: S31. Deduct the corresponding quantity of goods in the withheld inventory table; S32. Mark the withholding status and set the withholding validity period.
[0009] The above-mentioned high-concurrency inventory write-off method also has the following characteristics: step S4 includes the following steps: S41, sending the inventory update and order confirmation to the message queue of the background processing system for asynchronous execution; S42, the front end sends a response message to the client; S43. Determine whether the payment time exceeds the validity period. If so, release the withheld inventory and prompt the user to resubmit the request; if not, deduct the actual inventory.
[0010] The above-mentioned high-concurrency inventory write-off method also has the following characteristics: the step S4 further includes the following steps: S44. Update the inventory record according to the actual inventory deduction quantity; S45. Release the distributed lock.
[0011] In summary, the beneficial effects of this scheme are: The high-concurrency inventory write-off method provided by the present invention integrates distributed locks, optimistic lock mechanisms, withholding inventory, asynchronous processing and other methods to efficiently and accurately handle inventory management issues, improve processing speed, avoid overselling, and improve system stability. The high-concurrency inventory write-off method provided by the present invention has the effect of improving the system's processing capacity under large traffic impacts, ensuring the accuracy and consistency of inventory data, and optimizing user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] Figure 1 The present invention is a flowchart of the high-concurrency inventory write-off method. DETAILED DESCRIPTION
[0013] The technical solution of the present invention will be clearly and completely described below in conjunction with 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.
[0014] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments may be combined with each other.
[0015] The present invention will be further described below in conjunction with specific embodiments, but the present invention is not limited thereto.
[0016] In the accompanying drawings, Figure 1 The flowchart of the high-concurrency inventory write-off method described in the present invention is as follows: Figure 1 As shown, the high-concurrency inventory write-off method provided in this embodiment includes the following steps: S1, distributed lock phase, locks the inventory items to be modified; S2, optimistic locking stage, add a version number to the inventory record. Every time the inventory is updated, not only the inventory quantity needs to be updated, but also the version number needs to be checked to see if it is consistent with the one read; S3, withholding inventory stage: when the user submits an order or redemption request, the corresponding quantity is immediately deducted from the withholding inventory, the actual inventory is maintained, and the validity period of the withholding inventory is set. For orders that have not been paid for after the validity period, the withholding inventory is released; S4, asynchronous processing stage, the operations of inventory update and order confirmation are executed asynchronously through the message queue, and the front end immediately sends a response message to the customer until the processing is completed and the actual inventory is deducted.
[0017] In the above embodiment, step S1 includes the following steps: S11, user request processing, when a user initiates a purchase request or redemption request, the system distributes it to an available server node through a load balancer; S12: Distributed lock acquisition: the server node attempts to obtain the inventory operation lock of the product from the distributed lock service; S13. Determine whether the operation lock is occupied. If so, the request enters a queue or prompts the user to try again later. If not, proceed to step S2.
[0018] The above-mentioned high-concurrency inventory write-off method also has the following characteristics: step S2 includes the following steps: S21, optimistic lock check, after successfully acquiring the operation lock, the server node reads the current inventory and version number of the product from the database; S22, read the current inventory and version number of the product; S23. Determine whether the read version number is consistent with the latest version number in the database. If so, proceed to step S3. If not, a concurrency conflict occurs, prompting the user to resubmit the request.
[0019] It should be noted that by judging whether the read version number is consistent with the latest version number in the database, it is judged whether the inventory data has been modified by other things during the operation. If the inventory data has been modified during the operation, the update is rejected.
[0020] In the above embodiment, step S3 includes the following steps: S31. Deduct the corresponding quantity of goods in the withheld inventory table; S32. Mark the withholding status and set the withholding validity period.
[0021] In the above embodiment, step S4 includes the following steps: S41, sending the inventory update and order confirmation to the message queue of the background processing system for asynchronous execution; S42, the front end sends a response message to the client; S43. Determine whether the payment time exceeds the validity period. If so, release the withheld inventory and prompt the user to resubmit the request; if not, deduct the actual inventory.
[0022] It should be noted that a withholding inventory table is created to record the withholding situations that have not been booked. When the order is confirmed, the withheld inventory is converted into actual inventory for deduction. For operations that have exceeded the validity period but have not been paid or confirmed, the withholding records are automatically cleared and the withheld inventory is released.
[0023] In the above embodiment, step S4 further includes the following steps: S44. Update the inventory record according to the actual inventory deduction quantity; S45. Release the distributed lock.
[0024] Working principle: first, the combination of distributed locks and optimistic lock mechanisms can effectively alleviate the performance bottleneck of traditional single databases under high concurrency, reduce lock contention, and improve the system's concurrent processing capabilities, ensuring that inventory operations can be efficiently executed even under extreme traffic and preventing inventory overselling. Secondly, through the withholding inventory strategy and asynchronous processing mechanism, combined with intelligent data synchronization and verification algorithms, the data consistency between the database and cache, as well as between nodes in the distributed environment is ensured. Even in a complex network environment and under high load, the inventory information can be guaranteed to be accurate, thereby improving the user experience. Finally, through the instant response mechanism and withholding inventory strategy, users can quickly obtain operational feedback and participate smoothly even during peak activity periods, reducing waiting time and operation failure rate, enhancing user participation and satisfaction, and thus improving user trust and loyalty to the platform.
[0025] The above are only preferred embodiments of the present invention, and are not intended to limit the implementation methods and protection scope of the present invention. Those skilled in the art should be aware that all solutions obtained by equivalent substitutions and obvious changes made using the contents of the specification of the present invention should be included in the protection scope of the present invention.
Claims
1. A high-concurrency inventory write-off method, characterized in that: The method comprises the following steps: S1, distributed lock phase, locks the inventory items to be modified; S2, optimistic locking stage, add a version number to the inventory record. Every time the inventory is updated, not only the inventory quantity needs to be updated, but also the version number needs to be checked to see if it is consistent with the one read; S3, withholding inventory stage: when the user submits an order or redemption request, the corresponding quantity is immediately deducted from the withholding inventory, the actual inventory is maintained, and the validity period of the withholding inventory is set. For orders that have not been paid for after the validity period, the withholding inventory is released; S4, asynchronous processing stage, the operations of inventory update and order confirmation are executed asynchronously through the message queue, and the front end immediately sends a response message to the customer until the processing is completed and the actual inventory is deducted.
2. A high-concurrency inventory write-off method according to claim 1, characterized in that: The step S1 includes the following steps: S11, user request processing, when a user initiates a purchase request or redemption request, the system distributes it to an available server node through a load balancer; S12: Distributed lock acquisition: the server node attempts to obtain the inventory operation lock of the product from the distributed lock service; S13. Determine whether the operation lock is occupied. If so, the request enters a queue or prompts the user to try again later. If not, proceed to step S2.
3. A high-concurrency inventory write-off method according to claim 2, characterized in that: The step S2 comprises the following steps: S21, optimistic lock check, after successfully acquiring the operation lock, the server node reads the current inventory and version number of the product from the database; S22, read the current inventory and version number of the product; S23. Determine whether the read version number is consistent with the latest version number in the database. If so, proceed to step S3. If not, a concurrency conflict occurs, prompting the user to resubmit the request.
4. A high-concurrency inventory write-off method according to claim 1, characterized in that: The step S3 comprises the following steps: S31. Deduct the corresponding quantity of goods in the withheld inventory table; S32. Mark the withholding status and set the withholding validity period.
5. A high-concurrency inventory write-off method according to claim 4, characterized in that: The step S4 includes the following steps: S41, sending the inventory update and order confirmation to the message queue of the background processing system for asynchronous execution; S42, the front end sends a response message to the client; S43. Determine whether the payment time exceeds the validity period. If so, release the withheld inventory and prompt the user to resubmit the request; if not, deduct the actual inventory.
6. A high-concurrency inventory write-off method according to claim 5, characterized in that: The step S4 further comprises the following steps: S44. Update the inventory record according to the actual inventory deduction quantity; S45. Release the distributed lock.
Citation Information
Cited By
Quick sorting method and system for instant bills in different specifications
CN121352677A
A method and system for quickly sorting different specifications of instant tickets
CN121352677B
Full-process business management and analysis system for agricultural equipment sales
CN122086904A