SQL vs NoSQL | Difference between SQL & NoSQL | SQL Vs NoSQL Tutorial | SQL, NoSQL system design

 SQL

 1. Structure

        Table,row,column

        PreDetermined Schema

                Create table with all the defined datatypes and size.

                Then you can use the table

        Relations

            1:1,1:M,M:M

2. Nature

         Centralized data-all tables in the same database server

3. Scalability

        Vertical 

                Increase the RAM,Storage

        Horizontal -> NOT good for horizontal scaling

                Sharding

                        based on row and column - Not well supported

                         Some table data cannot be stored in different database server due to centrallized data 

4. Property: ACID

        Data integrity

        Consistency

        Isolation

        Durability


NoSQL

    Non Relational

    No SQL

    Not Only SQL

 1. Structure

        Unstructured data

            Key Value DB

                      {Key:value}

                      Search based on Key only, value is opaque can be string,integer,json but cannot be quered

                      <DynamoDB>   

            Document DB

                        JSON,XML

                        both Key and Value can be quered.

                        {Key:value}

                       <MongoDB>

            Column DB

                    Key Value

                              Key ->{Column:value}

            Graph DB

                    {Node, Edge(relationship)}

 2. Nature

         No Centralized - data can be distributed database server

3. Scalability

        Vertical 

                Increase the RAM, Storage

        Horizontal -> Good for horizontal scaling, as we can store data in node 

4. Property -BASE

        Basically Available-> Highly available DB due to replication.

        Safe State->State of data can be changed, as it is distributed, and will sync

        Eventually Consistency->Query then you may get slate data, but eventually you will get latest data after retry.


When to use which one?

Flexible Query Functionality

NoSQL does not support complex query

Basic Search use NoSQL

If Data is relational then use SQL

Data Integrity use SQL- (cannot lose a single transaction/consistency) -example banking, financial.

NoSQL->Handle big data, so losing data is of no impact.

High Availability, High Performance with some inconsistence then go for NoSQL because of distributed nature.



Comments

Popular posts from this blog

Microservice Pattern: SAGA

Microservice Pattern: Database per service Context