Design ecommerce website (part i)

In the last handful of days, many people requested us to go over eCommerce website. Not just has this subject been requested in quite a bit system design interviews, but additionally eCommerce websites are extremely popular today that many techniques and researches are produced for it.

Before digging into this subject, it’s easier to realise why design eCommerce web site is famous system design interviews. To begin with, building an eCommerce website requires such things as database design, system availability, concurrency consideration and so forth so on. All are very essential in today’s distributed systems. Additionally, everybody has utilized some eCommerce website like Amazon . com. If you’re generally interested in surroundings, you ought to have already considered this subject.

eCommerce model

Within our guideline 8 Things You should know Before a method Design Interview, we stated that the common technique of system design interview is beginning with easy and fundamental things rather of jumping into details directly. So how does one design the fundamental data structure of the eCommerce website? And just what concerning the database schema?

I’ll skip the information structure for user models accurately quite much like other applications. Let’s concentrate on the product. Within the simplest scenario, we want three major objects: Product, User and Order.

Product defines the fundamental model for any product within the shopping cart software. Some important fields include cost, the quantity left, name, description, and also the category. Category could be tricky here. Obviously you can turn it into a string field within the SQL database, however a better approach is to possess a Category table which contains category ID, name and perhaps additional information. Therefore the each product will keep a category ID.

Order stores details about all of the orders produced by users. So each row provides the product ID, user ID, amount, timestamp, status and so forth. Then when a person proceeds to checkout, we aggregate all of the records connected with this particular user to show within the shopping cart software (obviously we ought to remove products which were bought previously).

NoSQL in eCommerce

Within the above analysis, we’re utilizing a relational database like MySQL. The truth is, NoSQL database could be a better option for eCommerce website sometimes.

In situation lots of people have no idea about NoSQL, in layman’s term, NoSQL database attempts to store a lot of things in one row rather of multiple tables. For example, rather of getting another Order table, we are able to store all of the products a person has bought within the same row of User table. Consequently, when fetching a person, not simply will we obtain all of the private information, but additionally his purchase history.

Why can NoSQL be (slightly) better within this situation? Let’s use Product model for example. Suppose we’re selling books. An item has category book and a lot of attributes like author, publish date, version, the amount of pages etc. which SQL table might have 20 posts. That’s fine.

And today, we should also sell laptops. So an item also needs to store features of a laptop including brand, size, color etc.. Understandably, with increased groups introduced, the Product table might have a lot of posts. If each category has 10 attributes in average, it’s destined to be 100 posts with simply 10 groups supported!

However, for NoSQL database like MongoDB, an advantage is it supports large numbers “columns” such as this. Each row may have a high number posts although not all are set. It’s like storing JSON object like a row (actually, MongoDB is applying something much the same known as BSON). Consequently, we are able to just store all individuals attributes (posts) of the product in one row, which is what NoSQL database proficient at.

Concurrency

Let’s proceed to discuss scaling issues. When scaling an eCommerce web site to multiple machines, you will find loads of problems appearing. The most crucial factor is the fact that eCommerce website has almost zero ability to tolerate the majority of this issues.

Take concurrency for example. your house there’s just one book left within the store and 2 use it concurrently. With no concurrency mechanism, it’s absolutely entirely possible that have got it effectively. How can you achieve concurrency in eCommerce websites?

Let’s evaluate this step-by-step. From what we should learned from OS classes, we all know that lock is easily the most common method to safeguard common sources. Suppose both user A and B are interested exactly the same book. What are going to happens when A fetches the information relating to this book, convey a lock about this row to ensure that nobody else have access to it. When A finishes the acquisition (reduce the amount left), we release the lock to ensure that B have access to the information. Exactly the same approach should choose all of the sources which can solve the issue totally.

The above mentioned option would be known as pessimistic concurrency control. Even though it prevents all of the conflicts brought on by concurrency, however that it is pricey. Clearly, for each data access we have to create and to produce lock, which can be unnecessary more often than not.

Are we able to solve the issue with no lock?

Summary

We’ll discuss the answer for concurrency issue without needing a lock within the next publish. There are plenty of topics I’d prefer to cover about eCommerce websites.

Actually, many techniques are typical across all distributed systems, what’s important would be to compare the benefits and drawbacks of every approach and choose the one which works well with the specific application.

Within the next publish, we’ll continue discussing concurrency as well as discuss system availability and consistency.

Incidentally, if you wish to convey more guidance from experienced interviewers, you should check Gainlo that enables you to definitely have mock interview with engineers from Google, Facebook etc..

Resourse: http://blog.gainlo.co/index.php/2016/08/22/design-ecommerce-website-part/

How to Create an Ecommerce Website with WordPress ONLINE STORE! – 2017