Some ideas about ASP shopping Cart-application Tips

Source: Internet
Author: User
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 the problem in real projects. A search on Google, found a piece of my garden a netizen's point of view: The shopping cart should be a temporary storage of data modules, he placed it in the session object. The netizen said very reasonable, but I do not like this approach. If everyone stored it in the session object, thousands of users shopping together, presumably ASP.net server will bear a huge load. Perhaps our domestic website may be better, but what about Amazon's web site? The Amazon China site, the Joyo site, is not stored in the session object, because if I put the item in the shopping cart without submitting an order, the next time I log in, the shopping cart will have these items. So, I think they're probably putting the data in these shopping carts in the database.
Reply: Store your shopping cart in session, which seems to exist only in college courses or in some neglected internship programs. In fact, basically all E-commerce sites store the shopping cart data in the database. Here are some explanations and designs to note:
1, the session is not suitable for large data data storage, when more users will inevitably affect the performance of the server, which should be avoided.
2, the session has an accidental loss of the problem, or when the user accidentally shut down the browser, will cause all the items in the shopping cart lost, the user experience is very bad
3, cookies can solve the previous session of the problem, but the length of cookies, as well as the use of cookies when the communication costs, as well as security considerations, cookies are not suitable for shopping carts
4, a 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 the goods in the shopping cart, generally have the intention to purchase goods, but not necessarily become a real order, this time, the retention of this data, data mining, business analysis has a vital role
Question: 2. About concurrency?
I was in the development of my own simulation site, once thought of such a problem: if a customer on the site to put some books into the shopping cart, then these quantities of books should be subtracted from the inventory? That's what I did. I subtract the number of books in the cart from the database to prevent other users from seeing the "virtual" inventory (if not subtracted), so that other users can buy it. For example: The number of books in the inventory is 10, customer a will 10 into their own shopping cart, at this time customer B will also 10 into their own 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 and has an exchange with the database, it increases the burden on the data server. Amazon.cn in this respect do not very good, some days ago believe that you may have encountered 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. The incident really affected amazon.cn's credibility and wondered if their system had solved the problem, but now the Joyo price for a "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 of all, the burden of the database server, think about how many visits to the database per page to visit, and then think about a number of visits can be exchanged for a shopping cart operation (the number of visits depends mainly on the site usability design, this is another topic), so, While modifying the design here can alleviate some of the database pressure, this is not a bottleneck, Ding Co thinks it is not necessary to be too concerned here.
At present, the more common practice, shopping cart merchandise is not immediately deducted inventory, mainly in order to prevent someone through the shopping cart malicious occupation of goods, and generally give a redundancy, because most of the goods in the shopping cart will not enter the final successful orders, can not let the shopping cart affect sales, this is necessary to do. Inventory is usually deducted when the order is successfully submitted, that is, when the user submits the order, you also have an opportunity to prompt the user is not in stock, so there is no need to be in the shopping cart to deduct inventory. For a "success order", not all users submit orders are counted as successful orders, here is a process of automatic audit, this procedure is not easy to write, but it is very important, according to the previous data analysis, user behavior, user reputation and other empirical data source system in a few minutes automatically to complete an audit of orders, Audit strength and industry-related, so that most of the fake orders can be eliminated, some of which may also be automated audit of the single system referred to manual audits.
Here's a special case, there are some special items such as concert tickets, there may be an online choice of the behavior, this time to put a shopping cart after the seat becomes more useful, now is generally put on the shopping cart immediately after the seat, but a certain period of time did not become a real order words will automatically release, such as 10 minutes, While it is not possible to completely eliminate malicious occupation, most problems can be solved. Now ticket success orders and most other industries are not the same, the ticketing industry's online selection of successful orders to determine whether the success of the payment, that is, unless you give money, otherwise you can only leave you 10 minutes.
Question: 3. Order and order details with the shopping cart relationship
I think this problem may have been a big problem for such a 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, this question simple to think is not difficult: Two table orders and details, each column in the order table points to the corresponding columns in the schedule. The foreign key is the order number in the order table.
Reply: This question is relatively simple, one kind is puts in the shopping cart to be the order, take a status to identify, this state of the order is modifiable, shopping cart merged into the order system (pay attention to deal with the user login and non-login status); the second is a separate shopping cart table, and when the final order is submitted, Copy the information in the shopping cart into the order and order list. The latter one uses more, the specific choice depends on the industry and commodity attributes.
Question: 4. The production of the order number in the schedule?
This question inherits from question 3rd, I never know how to solve this problem. I have two solutions, one is using triggers and the other is programming. The former adds a detail to the customer each time a product is placed in a shopping cart, make sure that the order is generated after the purchase, and that changing the purchase status in the schedule to trigger triggers will generate an order number (the order number, of course, can either be programmed in the trigger or a column of the order form order number is set to automatically generate the ordinal number). The latter will determine the order number and then add 1 to generate the new order number. But I always feel very bad about these two options and wonder how the order number is handled in the commercial website.
Reply: First of all, I personally think that the trigger scheme is not desirable, the reason is not to say, otherwise it is a big lump. There are also two ways to do this, one is to automatically generate the number of order form, when the order is generated, write the order form first, then retrieve the order number and update the order list, and the other is to generate the order number according to the business rules, when the order number is known, the order record or the detail record can be, but to ensure that the detail records must have the order records eventually , or there will be a lot of weird details. The latter approach has two different approaches, one is that the order number is generated by the database, general use of temporary table, the advantage is that the whole business Universal serial number, the other is the order number by the program generated, the program can be generated when the GUID, but a better way is to use the order time plus the identification value, the time part can be based on order quantity to determine the size of the granularity, The identification part uses the ordinal number, the time granularity also must consider prevents other people to estimate your business volume (Khan ~ ~ ~ This is also another question, a lot of practice, see the situation, another day to write about the order number of the article generated, the first reply so much, probably enough information. )
Related Article

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.