user3222352
user3222352

Reputation: 11

Data model in NoSQL

Actually, I am a SQL developer. Now world is move to NoSQL, so I try to learn NoSQL like cosmos DB. In my mind one basic question come and I'm dwelling on that. How NoSQL support to business oriented applications. For example, I have 3 table in RDBMS they are customer, product and order. Here, customer and product are master tables, order is transactional table. Order table have references of both master's. In RDBMS created three separate table for the same, because in my form I must show product list in dropdown or list view so I created as separate master table. How to design data model in NoSQL, whether product separate table or not? I am looking forward.

Upvotes: 1

Views: 329

Answers (1)

Sunil Gollapinni
Sunil Gollapinni

Reputation: 169

For your example - Customer, Product and Order entities. you can design in the following way (document model):

Product

{
    "_id" : "p1",
    "name": "camera"
},
{
    "_id" : "p2",
    "name": "mobile"
}

Customer

{
    "_id" : "c1",
    "name": "sunil",
    "orders": [
        {
            "_id" : "999",
            "date": "05/05/2018",
            "product_id": "p1"
        },
        {
            "_id" : "888",
            "date": "02/09/2018",
            "product_id": "p2"
        }
    ]
}

From above you can make out that:

There are two tables in the document model compared to three in RDBMS. Product details are stored in the Product table. Orders are embedded in the Customer table (so no joins) along with Customer details.

In relational design, entity and its relation to other entities will be described and the queries and indexes are designed later. In RDBMS, Normalization is used to eliminate redundant data to make it storage efficient. Join queries can be used to get data together. But, joins are the culprit to performance and scale.

On NoSQL side, you get the capabilities like DBs supporting partition on table and also you need to identify how data(queries) is consumed to give a meaningful primary index to query by. The row document or columns should be designed to group data together that will be read together. With NoSQL, you de-normalize your schema to store in one row or document what would be multiple tables with indexes in a relational world. Grouping the data by key range provides for fast reads and writes by row key.

Upvotes: 3

Related Questions