Java Open source Fresh e-commerce platform discussion and solution of concurrency problem and lock mechanism in-oms Order system (source code can be downloaded)
Description: Discussion and solution of concurrency problem and lock mechanism in OMS order system of Java Open Source fresh e-commerce:
Origin of the problem
Suppose in an order system (take train ticket order system for example), user A, User B are to book a train ticket from Chengdu to Beijing, A, b in different ticket window at the same time inquires into a car sleeper, the next berth there is vacant. User A is hesitant to order Zhong Pu or lower berth, then User B decisively ordered the lower berth. When user a decides to book the lower berth, the system indicates that the lower berth has been booked, please re-select the bunk. In this system scenario, let's explore how the train ticket system handles concurrency events and how to use locking mechanisms to avoid duplicate bookings.
Scenario envisaged
Scenario 1:
In order to avoid duplicate bookings, most people will think before the booking operation, go to the database to check whether the bunk has been booked, assuming that the "bunk" database table added flag field flag (idle: 0; Booked: 1), if the value of the flag field of the query to the bunk is 1, then the reservation is unsuccessful, if the booking is 0 , and set the flag to 1. This scenario might be feasible in a system with a small volume of business. However, when the volume of business is large, especially the train ticket such business volume, there will be problems. The problem is that when user A, User B, while booking the same bunk, although the "simultaneous", but for database operations must be sequential, assuming a in the query of the berth flag, a value of 0, ready to book and set the value to 1, while B has been booked successfully, and has set flag to 1. A because there is no immediate query to the flag=1, so the booking is also successful, and flag is set to 1.
A flag=0 moment =t1 (enquiry)
B flag=0 moment =t2 (query)
B flag=1 moment =t3 (update)
A flag=1 moment =t4 (update)
This creates a duplicate booking, at the peak of the ticket purchase, the use of such a scheme, repeat booking inevitable.
Scenario 2:
We think of the use of database pessimistic lock to solve this problem, imagine if user a query to want to book tickets, User B simply can not query, only a a person to see, it is not the possibility of duplicate tickets, because no one to rob him. This scenario can be implemented as follows:
SELECT * FROM table where ... for update skip locked, the statement is to query the user to specify the conditions of the ticket information, and lock (for update), if there is a record has been locked automatically skip to the next record (skip locked), so who First query who can slowly consider the upper bunk or the lower berth. But is the train ticket system doing this? Obviously not, because this user experience is too bad, the ticket actually still many, but do not see can not buy, this obviously unreasonable.
Scenario 3:
We also think of the process to solve the concurrency problem, the simplest way is to use synchronized to deal with, but we need to know that a large-scale system is necessarily a cluster deployment, synchronized can only solve the single-node environment concurrency problem, To resolve this issue, you must rely on the global locking mechanism.
Scenario 4:
Now that we're back on the database, let's think about it. What if we use optimistic locks when querying, but what about using pessimistic locks before we make a reservation? For example, when we query:
SELECT * FROM table where ...
Both User A and User B are queried for the same ticket information (Zhong Pu and bunk), and user A or User B makes a pessimistic lock at the time of booking:
SELECT * FROM table where ... for update (pessimistic lock on reserved tickets only)
At this time the latter at the time of booking, unable to obtain the lock of the record, nature can not book, avoid the problem of duplicate booking.
Directory:
1.Java Open Source fresh e-commerce platform-system introduction https://www.cnblogs.com/jurendage/p/9012355.html
2.Java Open Source fresh e-commerce platform-system architecture and technology selection (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9012922.html
3.Java Open Source fresh e-commerce platform-profit model detailed (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9016411.html
4.Java Open Source fresh e-commerce platform-user table design (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9017912.html
5.Java Open Source fresh e-commerce platform-design of commodity table (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9022917.html
6.Java Open Source fresh e-commerce platform-Design of order form (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9029467.html
7.Java Open Source fresh e-commerce platform-payment module design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9034444.html
8.Java Open Source fresh e-commerce platform-shopping cart module design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9039195.html
9.Java Open Source fresh e-commerce platform-recommended system module design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9044283.html
10.Java Open Source fresh e-commerce platform-financial system module design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9049318.html
11.Java Open Source fresh e-commerce platform-bill module design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9053417.html
12.Java Open Source fresh e-commerce platform-the design and architecture of the withdrawal module (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9053523.html
13.Java Open Source fresh e-commerce platform-order module design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9059304.html
14.Java Open Source fresh e-commerce platform-search module design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9062649.html
15.Java Open Source fresh e-commerce platform-after-sales module design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9066307.html
16.Java Open Source fresh e-commerce platform-monitoring module design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9070442.html
17.Java Open Source fresh e-commerce platform-Exception module design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9075219.html
18.Java Open Source fresh e-commerce platform-performance optimization and server optimization design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9081062.html
19.Java Open Source fresh e-commerce platform-security design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9087581.html
20.Java Open Source fresh e-commerce platform-coupon design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9091587.html
21.Java Open Source fresh e-commerce platform-Notification module design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9095078.html
22.Java Open Source fresh e-commerce platform-buy module design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9098368.html
23.Java Open Source fresh e-commerce platform-server deployment design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9103339.html
24.Java Open Source fresh e-commerce platform-system report design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9108863.html
25.Java Open Source fresh e-commerce platform-source address announcement and thinking and suggestions https://www.cnblogs.com/jurendage/p/9114796.html
26.Java Open Source fresh e-commerce platform-RBAC System Authority design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9120168.html
27.Java Open Source fresh e-commerce platform-Logistics and distribution design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9124947.html
28.Java Open Source fresh e-commerce platform-Inventory management design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9130455.html
29.Java Open Source fresh e-commerce platform-Sales management design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9131557.html
30.Java Open Source fresh e-commerce platform-e-commerce promotion Business Analysis design and system architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9137815.html
31.Java Open Source fresh e-commerce platform-one-time code reconstruction of the actual case (source can be downloaded) https://www.cnblogs.com/jurendage/p/9143105.html
32.Java Open Source fresh e-commerce platform-the design and structure of commodity price (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9148906.html
33.Java Open Source fresh e-commerce platform-timer, scheduled task Quartz design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9153835.html
34.Java Open Source fresh e-commerce platform-high concurrency design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9159020.html
35.Java Open Source fresh e-commerce platform-Technical solutions and documentation download (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9162190.html
36.Java Open Source fresh e-commerce platform-points, coupons, member discounts, check-in, pre-sale, carpool, bargaining, second kill and Sweepstakes and other promotional module architecture design (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9165594.html
37.Java Open Source fresh e-commerce platform-supply chain module design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9171467.html
38.Java Open Source fresh e-commerce platform-member points system design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9176010.html
39.Java Open Source fresh e-commerce platform-redis Cache in the product design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9181380.html
40.Java Open Source fresh e-commerce platform-product unlimited pole catalogue design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9185990.html
41.Java Open Source fresh e-commerce platform-logistics dynamic rate, free shipping and fixed freight design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9189736.html
42.Java Open Source fresh e-commerce platform-product SPU and SKU data structure design and architecture (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9194551.html
43.Java Open Source fresh e-commerce platform-you should keep some learning attitude and learning method (source code can be downloaded) https://www.cnblogs.com/jurendage/p/9197096.html
Java Open source Fresh e-commerce platform-java backend generated token architecture and design details (source can be downloaded), If you need to download, you can download under my github.
https://github.com/137071249/
Group number: 168096884
Java Open source Fresh e-commerce platform discussion and solution of concurrency problem and lock mechanism in-oms Order system (source code can be downloaded)