1. Overall design
Why to use the mid-platform architecture has been explained in the previous several articles, here will introduce the function of the base layer and platform layer.
1. The base layer
Publish, edit, put on the shelf, take off these functions we should be more familiar with.
Review: Whether approval is required to allow the shelves
Marking: To mark goods, for example to participate in an event
Sku management: Relationship between goods and SKUs
Association relation: association relation between front and back end commodities, combination commodities, etc
Front and back end goods: The front end goods face the user and the back end goods face the warehouse
Category: Commodity category, front end category
Attributes: commodity attributes, category attributes and so on
2. The platform layer
Commodity management: The basic operation of commodities
Merchandise collection: Manages the merchandise that the user collects
Product snapshot: Saves each snapshot version of an edited product
Activity marking: Map different tags to product attributes according to different activities
Sales management: sales statistics and ranking of goods
Browsing history: User browsing history
Search: Search for goods from different dimensions
Ii. Concept definition
1. Item-sku
Item stands for product and SKU stands for product
For example: Item corresponds to iPhone 7, but iPhone 7 has black, and SKU corresponds to iPhone 7 with black
The corresponding relationship is as follows:
2. Front-end and back-end goods
Front-end goods: user-facing, displayed and sold in a store, a virtual concept.
Back-end goods: For warehouse physical goods, such as a computer to create a back-end goods. It has a close relationship with the warehouse, synchronous inventory, warehousing and warehousing operations are synchronized to the commodity information.
There is a mapping between front-end goods and back-end goods. For example, if the front-end goods are computers, the back-end goods correspond to one computer.
Back-end combination commodities: Some commodities can be sold individually or in A package. For example, the discount of computer set is A combination commodity A, which is composed of computer B, mouse C and keyboard D.
So there’s A mapping A->(1B,1C,1D). At this time, if it needs to be sold in the mall, A front-end commodity can be created to associate with A.
3. Association
The association relationship includes the mapping relationship between front-end goods and back-end goods, and the relationship between back-end composite goods and single goods. Based on this relationship, you can determine which warehouses the item is in stock, how many should be shipped, and so on.
4. Product snapshot
Each time the product is edited, it will save a snapshot. On the one hand, it can record the operation log, and on the other hand, it can be traced back. For example, the order will save a snapshot version of the product, according to which the product information at the time of the order can be found.
5. Product marking
Marking is a tag, such as a commodity to a dozen activities, so how to save on goods, we can use a long field flag to save, is 64 long, each represent a type of activity, 0 (no, 1 is represented, through the study of the binary operation can complete activities of flag is updated information.
6. Category
Categories are also divided into front and back end categories. The front end category is user-oriented, has navigation function, and is changeable.
The back-end category is directly related to the product and is stable. There are mappings between the front and back end categories.
7. The attribute
For example, the black iPhone 7 has the property color and the property value is black.
Iii. Technical design
1. The diagram
2. Describes the key fields of the product
Commodity list is based on the design of sub-database sub-table.
Category_id: Price and category are in a one-to-one relationship, and you need to get the category of the product first when you create the product. Determine whether the publication of goods under this category needs to be reviewed, and the goods must be filled with the attributes associated with this category and saved to the goods.
Item_pattern: Commodity type: includes physical goods, virtual goods and service goods. Why should this field be included? Physical goods need to be associated with warehouse physical goods. Virtual goods don’t need to be associated, like e-books, videos, etc. Service goods as another special way of processing, such as three-year warranty, door-to-door delivery, etc., are as a kind of service, we abstract it into service goods, together with the order when placing an order, the advantage of this is easy to expand.
Item_type: Item type: includes front-end and back-end goods. Either a combination of goods or an extended type of goods.
Shop_id: indicates the owning store
Selle_id + ITEM_code: merchant ID and merchant code. If the goods are imported by the erp system of the merchant, these two fields are unique and can uniquely identify the goods in the merchant system.
Flag: indicates the flag bit for binary marking.
Biz_type: indicates the service platform to which services are separated based on this field.
Feature: Extends the field, storing the attributes of goods in it, and storing the information added in the future without changing the table structure.
3. Design of item history table Item_history
The history table is the commodity data table that has been deleted, so why should the deleted data be saved? This is the design principle of the e-commerce system. The data of any table is only logically deleted, not physically deleted. So many tables are marked with an IS_DELETE field to indicate whether or not they have been deleted.
1) There is a unique key constraint in the commodity table (seller_id, ITEM_code). If the commodity table is deleted and placed in the original table, when the merchants synchronize the commodity table again, the unique key constraint will be affected because the two fields are the same, but they cannot be deleted, so the data will be moved to the history table. 2) The accumulated data of the commodity table will become larger and larger over time. Moving out the deleted data will help improve the performance of the original table.
4. Product snapshot design
As the object of e-commerce transactions, any change to the goods is very important, so the storage of snapshots is to keep a record of each change. On the other hand, there are scenarios similar to trading orders, which require the information of goods at that time in order to deal with complaints and protect rights.
The snapshot data is larger, because each change generates a copy of the data, so it cannot be stored in a database, but in external storage. You need to query itemId+snapshotVersion, commodity id and snapshotVersion.
5. Product marking design
Start by defining an activity type enumeration class that says what activity each represents. Any other type is fine, but it just marks that the item has some property.
If flag = 0; Now the commodity participates in an activity, and the third flag represents the activity, so the marking process is;
flag=flag | (1 << 2)
Copy the code
De-label the same logic.
6. Design of commodity extension field
Is not only the goods table, we often encounter in the work, in the process of iteration in demand, will certainly have a need to add fields, but if we add fields are not key field () is not used for retrieval, such as commodity list if the backend now need to store a commodity width is high, the quality, as well as some information such as origin, We can do this by extending the fields and eliminating the need to add columns to the inline table. The extended feature field is actually a string in Json format, with a certain length reserved for later adding key-value pairs.
For example, before adding, it is stored like this:
{" length ": 10," width ": 12," height ": 20}Copy the code
When you add the place of origin
{" length ": 10," width ": 12," height ": 20," region ", "HZ"}Copy the code
However, the update must be accompanied by the version update, otherwise the concurrency will occur data overwrite. This is also why all tables in the database have a Version field: data update optimistic lock control.
7. Product sales statistics & Ranking
In fact, sales volume is not an attribute of the commodity itself, because sales volume is dynamically calculated according to the volume of trading orders, but general e-commerce sites will have the demand for ordering sales, so how to achieve this? Must be a search engine to do, because the search conditions are too much, too many sorting conditions, database index can not support a variety of combined query, sorting. So we will according to the business demand, the general sales statistics once a day to meet the demand. Add a sales field in the commodity index, count the sales volume from the order by regular task every day, and then push it to the search engine in the way of message, search engine can help us to achieve this function when searching sorting.
8. Product category design
Category design will be covered in more detail in subsequent articles. It includes foreground category, background category, category tree construction, category cache design, category attributes and so on.
9. Product search design
Search design will be covered in more detail in a future article. Search design includes search engine selection, storage structure design, index building, search, and general search framework and so on.
Four,
This paper introduces the hierarchical design of commodity system, and the corresponding functions and functional design of each layer. In the follow-up, the design points and details of the commodity system will be introduced in detail, such as categories and search. In addition, there is a lot of middleware encapsulation involved in the implementation, so generic components (generic search framework, messaging framework) will be covered later.
For more articles, visit http://www.apexyun.com/
Public id: Galaxy 1
Contact email: [email protected]
(Please do not reprint without permission)