Question: 1. Should the data in the shopping cart be stored in the database?
I particularly want to know how those real software engineers think about this issue in real projects. A search on Google, found an article in our garden, a netizen's view: The shopping cart should be a temporary storage data module, he stored in the session object. The netizen is very reasonable, but I do not like this approach. If everyone stores it in the session object and thousands of users are shopping together, the ASP. NET Server is bound to bear a huge load. Maybe like our domestic site may be better, but want to Amazon such a site, how to do it? The Amazon China site, which is Joyo's website, is not stored in the session object because I will have these items in my shopping cart the next time I sign in, if I don't submit an order for the items I put into my shopping cart. Therefore, I think they may have put the data in these shopping carts into the database.
Reply: Storing the shopping cart in the session seems to exist only in the course design of the university or in some of the internship programs that no one cares about. In fact, all of the basic ecommerce sites store the shopping cart data in the database. Here are some explanations and designs to be aware of:
1, the session is not suitable for large data storage, when the user is more often will affect the performance of the server, this should be avoided.
2, the session there is an accidental loss of the problem, or when the user accidentally close the browser, will cause the shopping cart items are lost, the user experience is not good
3. Cookies can solve the problem of the previous session, but the limitation of the length of the cookies, the communication overhead when using cookies, and the security considerations, cookies are not suitable for shopping carts.
4, the better user experience is, regardless of user login or not, can be recorded in a certain period of time shopping cart status, which requires the database shopping cart can not be bundled with the user too dead
5, put in the shopping cart of goods, generally have the intention to buy goods, but not necessarily will become a real order, at this time, to retain this data, data mining, business analysis has a vital role
Question: 2. About concurrency?
When I was developing my own mock-up website, I thought of the question: If a customer puts some books into a shopping cart on the website, should the number of books be subtracted from the inventory? I did that at the time. I subtract the number of books in my shopping cart from the database to prevent other users from seeing the "virtual" inventory quantity (if not subtracted, then other users can buy it.) For example: The number of books in inventory is 10, customer a will 10 into their own shopping cart, at this time customer B will also put 10 in their shopping cart, then who will buy this book will become a contradiction). But the result of my doing this is that every time a customer updates a shopping cart, there is a communication with the database, which increases the burden on the data server. amazon.cn do in this area is not very good, some days ago I believe you may have met when the purchase of "in-depth understanding of the operating system," a book, originally generated orders, but the next day to inform the shortage of things. This incident really affected amazon.cn's credibility and wondered whether their system had solved the problem now, but now the Joyo price of the "deep understanding of the operating system" has changed. Do not know how the master is how to solve this problem, you are welcome to write their own successful experience in the comments.
Reply: First talk about the burden of the database server, think about how many times each access to a page to the database, and then think about the number of visits in order to put a shopping cart operation (the number of visits mainly depends on the usability of the site design, this is another topic), so, Although modifying the design here can alleviate some of the database pressure, but here is not the bottleneck, do not need to be too concerned about here.
At present, the most common practice, shopping cart products are not immediately deducted inventory, mainly to prevent people through the shopping cart malicious occupation of goods, in addition to generally give a redundant amount, because most of the goods in the shopping cart will not enter the final successful order, can not let the shopping cart affect sales, this must be done. Inventory is generally deducted when the order is successfully submitted, that is, when the user submits the order, you also have a chance to remind the user that there is no inventory, so there is no need to put in the shopping cart when the inventory is deducted. For "Successful orders", not all the user submitted orders are counted as a successful order, here is a process of automatic review, this program is not good to write, but it is very important, based on the previous data analysis, user behavior, user reputation and other empirical data for the system in a few minutes automatically completed an audit of the order, The intensity of the audit is related to the industry, which can eliminate most of the fake orders, some of which may also be referred to the Automated Audit system manual review.
Here is a special case, there are some special items such as concert tickets, there may be online seat selection behavior, this time to put a shopping cart after the seat becomes more useful, the current practice is to put the shopping cart immediately after the seat, but a period of time has not become a real order automatically released, such as 10 minutes, Although it is not possible to completely eliminate the hostile seat, most problems can be solved. Now the success of ticketing orders and most of the other industries are not the same, the ticket industry online selection of successful orders to determine whether the success of the payment, that is, unless you pay the money, otherwise you can only leave 10 minutes.
Question: 3. The relationship between order and order details and shopping cart
I think this question may have been a big problem for this kind of website! Two days ago, CSTP's teacher Chen also interviewed me on the phone, I was very nervous, the question is not very clear. In fact, the simple thought is not difficult: Two table orders and details, each column in the order table points to the corresponding column in the schedule. The foreign key is the order number in the order form.
Reply: This question is relatively simple, one is to put in the shopping cart is the order, take a status to identify, this state of the order is modifiable, shopping cart merge into the order system (pay attention to handle user login and non-login status); the second is a separate shopping cart table, when the final order is submitted, Copy the information in the cart into the order and order schedule. The latter is more used, depending on the industry and commodity attributes.
Question: 4. What is the order number generation in the schedule?
This question inherits from question 3rd, and I have never known how to solve this problem. I have two solutions, one for using triggers and the other for programming. The former adds a detail to the customer each time a product is placed in the shopping cart, confirms that the purchase order is made, changes the purchase status in the schedule to trigger the trigger will generate an order number (of course, the order number can either be programmed in the trigger or a column of the order form is set to automatically generate the sequence number). The latter will determine the order number and then add 1 to generate a new order number. But these two scenarios I always feel very bad, I would like to know how to deal with the order number in the commercial website.
Reply: First I personally think that the proposal of the trigger is not advisable, the reason is not much to say, otherwise is a big lump. There are also two approaches, one is the order table automatically generated number, when the order is generated, the order form is written first, and then retrieve the order number and then update the order schedule, the other is to generate order number according to business rules, when the order number is known as the order record or the detail record can be, but to ensure that the detailed records must have order , or there will be a lot of weird details. The latter approach has two approaches, one is that the order number is generated by the database, the general use of temporary tables, the advantage is that the full service generic serial number, the other is the order number is generated by the program, the program can use the GUID when generated, but the better way is to use the order time and identification value, the time part can be based on the The identification part uses the ordinal number, the time granularity also must consider to prevent others to be likely to count your business volume (sweat ~ ~ ~ This is also another problem, many practices, to see the situation, another day to write an article about order number generation, first reply so much, probably enough information ... )
"Ideas about Shopping carts"