Thoughts on shopping cart

Source: Internet
Author: User
Source: Http://www.cnblogs.com/superwulei/archive/2008/11/15/1334332.html Bytes.

Today, I want to improve the sales system of my book again. When I started to want to buy the cart module, my doubts followed.

1. Should the data in the shopping cart be stored in the database?

I especially want to know how real software engineers consider this issue in real projects. After a search on Google, I found a view from a netizen in the garden: the shopping cart should be a module for temporary data storage. He stored it in the session object. This netizen said it makes sense, but I do not like this practice. If everyone stores it in the session object and thousands of users shop together, the ASP. NET Server will surely bear a huge load. Maybe our website in China may be better, but what should I do if I want a website like Amazon? The Amazon China website, or Joyo website, does not store it in the session object, because if I did not submit an order for the items in the shopping cart this time, these items will be available in the shopping cart after the next login. Therefore, I think they may have put the data in the shopping cart into the database.

2. About concurrency?

When I was developing my own simulated website, I thought of the following problem: if a customer puts some books into the shopping cart on the website, should these books be deducted from the inventory? At that time, I did this. I subtract the number of books in the shopping cart from the database to prevent other users from seeing the inventory quantity of "virtual" (if not, other users can purchase it. For example, if the number of books in the inventory is 10, then Customer A puts 10 books in its own shopping cart, and customer B also puts 10 books in its own shopping cart, so who will purchase this book will become a conflict ). However, the result is that every time the customer updates the shopping cart, he will communicate with the database, increasing the burden on the data server. Amazon.cn is not doing well in this regard. I believe that you may have created an order some days ago when you purchased the book "Understanding the operating system in depth, however, the problem of out-of-stock was reported the next day. This event has indeed affected amazon.cn's credibility. I don't know if their system has solved this problem, but now the Joyo price of the book "Understanding the Operating System" is far from the past. I don't know how experts solve this problem. You are welcome to write your successful experiences in comments.

3. Relationship between order and order details and shopping cart

I think this problem may always be a big problem for such websites! Two days ago, CSTP's teacher Chen also interviewed me on the phone. I was very nervous and did not answer the question clearly. In fact, it is not difficult to simply think about this problem: orders and details in two tables, each column in the order table points to the corresponding column in the list. The foreign key is the order number in the order table.

4. What is the generation of the order number in the detail table?

This problem inherits from 3rd problems, and I have never known how to solve it. I have two solutions: trigger and programming. The former adds a detail to each item in the shopping cart, and generates an order after confirming the purchase, changing the purchase status in the detail table triggers the trigger to generate an order number (of course, this order number can be programmed in the trigger or set a column of the order number in the order table to automatically generate an order number ). The latter judges the order number and adds it to 1 to generate a new order number. However, I always think these two solutions are very bad. I really want to know how to handle the order numbers on commercial websites.

Looking at the above, it has become a problem set.

 

Problem:1. Should the data in the shopping cart be stored in the database?
I especially want to know how real software engineers consider this issue in real projects. After a search on Google, I found a view from a netizen in the garden: the shopping cart should be a module for temporary data storage. He stored it in the session object. This netizen said it makes sense, but I do not like this practice. If everyone stores it in the session object and thousands of users shop together, the ASP. NET Server will surely bear a huge load. Maybe our website in China may be better, but what should I do if I want a website like Amazon? The Amazon China website, or Joyo website, does not store it in the session object, because if I did not submit an order for the items in the shopping cart this time, these items will be available in the shopping cart after the next login. Therefore, I think they may have put the data in the shopping cart into the database.

Reply:Store the shopping cart in the session, which seems to only exist in university course design or some unattended practice projects. In fact, almost all e-commerce websites store shopping cart data in the database. The following are some explanations and Design Notes:
1. sessions are not suitable for storing large amounts of data. When there are many users, they will inevitably affect server performance, which should be avoided.
2. The session may be accidentally lost, or when the user accidentally closes the browser, all items in the shopping cart will be lost, resulting in poor user experience.
3. Cookies can solve the session issue in the previous article. However, cookies are not suitable for shopping carts due to their length limitation, communication overhead when cookies are used, and security considerations.
4. A good user experience is that the shopping cart status can be recorded within a certain period of time, regardless of whether a user logs on or not. This requires that the shopping cart in the database cannot be bound to the user too much.
5. items placed in the shopping cart are generally purchased items, but they are not necessarily real orders. At this time, the data is retained, it plays a vital role in data mining and business analysis.

Problem:2. About concurrency?
When I was developing my own simulated website, I thought of the following problem: if a customer puts some books into the shopping cart on the website, should these books be deducted from the inventory? At that time, I did this. I subtract the number of books in the shopping cart from the database to prevent other users from seeing the inventory quantity of "virtual" (if not, other users can purchase it. For example, if the number of books in the inventory is 10, then Customer A puts 10 books in its own shopping cart, and customer B also puts 10 books in its own shopping cart, so who will purchase this book will become a conflict ). However, the result is that every time the customer updates the shopping cart, he will communicate with the database, increasing the burden on the data server. Amazon.cn is not doing well in this regard. I believe that you may have created an order some days ago when you purchased the book "Understanding the operating system in depth, however, the problem of out-of-stock was reported the next day. This event has indeed affected amazon.cn's credibility. I don't know if their system has solved this problem, but now the Joyo price of the book "Understanding the Operating System" is far from the past. I don't know how experts solve this problem. You are welcome to write your successful experiences in comments.

Reply:First, let's talk about the burden on the database server, and think about the number of accesses to the database each time a page is accessed, then I thought that only one shopping cart operation would be possible after multiple visits (the number of visits mainly depends on the ease-of-use design of the website. This is another topic). Therefore, although modifying the design here can reduce the pressure on some databases, it is not a bottleneck here. Ding Xue believes that it does not need to be too concerned here.

Currently, the general practice is that goods in the shopping cart will not be immediately deducted from the inventory, mainly to prevent malicious use of goods through the shopping cart. In addition, a redundant amount is usually given, because most of the items in the shopping cart do not enter the final successful order, and the shopping cart cannot affect sales, this is required. Inventory is generally deducted when the order is successfully submitted, that is, when the user submits the order, you have another chance to prompt that the user has no inventory, so there is no need to deduct the inventory when it is placed in the shopping cart. For "successful orders", not all orders submitted by users are regarded as successful orders. Here is an automatic ticket review process.ProgramIt is hard to write, but it is really important. based on empirical data such as previous data analysis, user behavior, and user reputation, the system will automatically review the order within several minutes, the review intensity is related to the industry, so that most fake orders can be eliminated, and some of them may need to be transferred to manual review by the automatic review system.

There is a special case where some special products, such as concert tickets, may be online seat selection. In this case, it is more useful to leave a seat after the shopping cart, the current practice is generally to leave a seat immediately after the shopping cart, but it will be automatically released if it is not a real order for a period of time, for example, ten minutes, although it is impossible to completely prevent malicious occupancy, however, most problems can be solved. Tickets are now different from most other industries in terms of tickets. The ticket industry's online seat selection success order is determined by whether the payment has been successful, that is, unless you have paid, otherwise, you can only stay for 10 minutes.

Problem:3. Relationship between order and order details and shopping cart
I think this problem may always be a big problem for such websites! Two days ago, CSTP's teacher Chen also interviewed me on the phone. I was very nervous and did not answer the question clearly. In fact, it is not difficult to simply think about this problem: orders and details in two tables, each column in the order table points to the corresponding column in the list. The foreign key is the order number in the order table.

Reply:This problem is relatively simple. One is to put the order in the shopping cart and identify it with a status. In this status, the order can be modified, the shopping cart is merged into the Order System (handle user logon and non-Logon statuses). The second is a separate shopping cart table. When the order is finally submitted, copy the information in the shopping cart to the order and order list. The latter is used more. The specific choice depends on the industry and product attributes.

Problem:4. What is the generation of the order number in the detail table?
This problem inherits from 3rd problems, and I have never known how to solve it. I have two solutions: trigger and programming. The former adds a detail to each item in the shopping cart, and generates an order after confirming the purchase, changing the purchase status in the detail table triggers the trigger to generate an order number (of course, this order number can be programmed in the trigger or set a column of the order number in the order table to automatically generate an order number ). The latter judges the order number and adds it to 1 to generate a new order number. However, I always think these two solutions are very bad. I really want to know how to handle the order numbers on commercial websites.

Reply:First of all, I personally think that the trigger solution is not advisable. I don't have much reason to say, otherwise it would be a huge deal. There are also two methods here. One is to automatically generate a number for the Order table. When an order is generated, it is first written into the Order table, then the order number is retrieved, and then the order list is updated; the other is to generate an order number based on business rules. Once the order number is known, you can generate an order record or a detailed record. However, make sure that the detailed record will eventually have an order record, otherwise, there will be a lot of weird details. There are two other methods for the latter: one is that the order number is generated by the database and the temporary table is generally used. The advantage is that the general sequential number can be used throughout the business, and the other is that the order number is generated by the program, the GUID can be used when the program is generated, but the better way is to use the order time plus the id value. The time part can be determined based on the order amount, and the identification part uses the sequential number, time granularity should also be considered to prevent others from making statistics on your business volume (Khan ~~~ This is also another problem. Many practices, depending on the situation, will write an order number generated when you are free in the next day.ArticleSo many replies, probably enough information ......)

Thank you for pointing out your shortcomings!

Copyright Disclaimer: This article was originally published in the blog park by Ding Xue

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.