MongoDB – Design of Product Catalog Documents Structure

Ecommerce with Node.js, MongoDB, Elasticsearch

                           In this article, we will see the product catalog database design and its associations. The below diagram explains the entities involved and their associations.

Mongodb product catalog document structure and associations

                Let me justify the above entities associations, as MongoDB has an embedded document approach and refer one document to another document.

Product to Category association chosen as a reference-based approach. Because the product can be associated with multiple categories and categories can be modified by business users. So when the category goes with modification, I don’t want to update the products belongs to that category.

Product to Reviews association chosen as a reference-based approach. Because the reviews are user-generated content and it will grow over the period. If I choose reviews as embedded documents, then whenever the review is given by the shoppers, then the product should undergo for update and  MongoDB has a limit on the single document size as 16 megabytes. The other reason is, some times we don’t want to manage reviews in our e-commerce system rather we will go with 3rd party integrations like Bazzarvoice or Yotpo kind of solutions. Going with the reference-based approach will enable us to detach the in-house management of the review system and choose above said 3rd party solutions.

Product to Inventory association, here again, I have chosen a reference-based approach. Because, the inventory is referenced by multiple systems like a customer service center, point of sales(POS) and online system, etc. Some times inventory may not be part of an e-commerce system rather it is maintained by ERP systems. In that case following the reference-based approach enable us to remove managing of inventory in the e-commerce system and use 3rd party inventory system.

The detailed field list of each entities document is given below.

Catalog Document Structure:

mongodb product catalog document structure and associations

Category Document Structure:

mongodb product catalog document structure and associations

Product Document Structure:

mongodb product catalog document structure and associations

Inventory Document Structure:

mongodb product catalog document structure and associations

Reviews Document Structure:

mongodb product catalog document structure and associations

If anyone wants to provide inputs or want to debate on the above product catalog design, it is very much appreciated.

Advertisement

Siva Janapati is an Architect with experience in building Cloud Native Microservices architectures, Reactive Systems, Large scale distributed systems, and Serverless Systems. Siva has hands-on in architecture, design, and implementation of scalable systems using Cloud, Java, Go lang, Apache Kafka, Apache Solr, Spring, Spring Boot, Lightbend reactive tech stack, APIGEE edge & on-premise and other open-source, proprietary technologies. Expertise working with and building RESTful, GraphQL APIs. He has successfully delivered multiple applications in retail, telco, and financial services domains. He manages the GitHub(https://github.com/2013techsmarts) where he put the source code of his work related to his blog posts.

Tagged with:
Posted in ecommerce, MongoDB, NoSql
10 comments on “MongoDB – Design of Product Catalog Documents Structure
  1. JP says:

    Hi, great article.

    Could you please explain which information you recommend to save in a RDBMS DB instead of in a NoSQL one? I got confused because, por instance, I would have thought that product inventory transaction should be acid.

    Or, does the info with eventual consistency should be updated in a nosql database?

    Thanks in advance,
    Best regards

    • You can keep transactional data also in NoSql. For example, MongoDB. You can keep order or customer information in MongoDB and make sure you update or insert the entire document at once. Or you can go with Cassandra where you can get eventual consistency.

  2. soengkanel says:

    what is difference id supplied by and supplied by mongodb , could help to explain ?

  3. soengkanel says:

    what is the reason you put “catalog_ref_id” in Inventory Document Structure

  4. Hi, Great series! Looking forward to next article of the series, specially integration between mongo and Elasticsearch.

  5. sravan says:

    Plz can u explain diff b/w MongoDB and other DB?

    • Other DB means? RDBMS?

      If so here are some of the differences.

      RDBMS:

      1. Follows schema. The data will be normalized and will be stored in tables. The schema is defined before putting the data.
      2. Follows ACID principles. Suitable for transnational data
      3. As the data is normalized, requires JOINS to get the data from multiple tables. This impacts the performance.

      MongoDB:

      1. Schemaless. No need to define the data model prior to put the data. The data will be stored as documents
      2. No support for ACID principles. Not suitable to handle transnational data.
      3. As the data is not normolized, no need to use JOINS to get the data. Provides better read performance.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Dzone.com
DZone

DZone MVB

Java Code Geeks
Java Code Geeks
OpenSourceForYou
%d bloggers like this: