SQL vs NoSQL

SQL / Structured / Relational NoSQL / unStructured / nonRelational
Examples Amazon(Aurora, RDS), MySQL, postgreSQL, mariaDB
  • Semistructured: Amazon (S3, dynamoDB), Apache Cassandra
  • Unstructured: Amazon S3, Apache CouchDB, MongoDB
  • Types - ORDBMS(Object RDBMS):RDBMS build on OOD.Eg:PostGreSQL
    - RDBMS: mySQL
    a. KEY-VALUE DB: redis, Amazon dynamoDB, Voldemort, sled(rust)
    b. WIDE-COLUMN DB: Stores data as columns instead of rows. Eg: Cassandra, HBase
    c. DOCUMENT DB: Data is stored in documents(XML, JSON, binary) Eg: mongoDB, Amazon dynamoDB.
    d. GRAPH DB: Data is stored in form of graph.Eg: Neo4J, HyperGraphDB
    Advantage 1. Super low latency
    2. Data are unstructured, or you do not have any relational data
    3. Store a massive amount of data
    4. Need to serialize and deserialize data (JSON, XML, YAML, etc.)
    Disadvantage 1. Join operations are not supported
    Format Table(Records searched using primary key)
    
    //Books Table
    
    | book-id(pk) | title | author | genre | comments |
                        
    <key, value> or xml or json or objects
    Example: Book data stored in mongoDB in json format
    
    // Same as books table
    /////// entry-1 /////////
    {       
        "_id": ObjectId("5f85e7a06921e55c279b15a0"), //Primary key
        "title": "GumsRoad",
        "author": {
            "name": "Douglas Adams",
            "birth_year": 1952
        },
        "genre": "Science Fiction",
        "comments": [
            {
            "user": "Alice",
            "text": "One of my favorites!"
            },
            {
            "user": "Bob",
            "text": "Hilarious and clever."
            }
        ]
    }
    ////////// entry-2
    (Fields in json document can vary) /////////
    {
        "_id": ObjectId("122312141241241"),     
        "title": "HedgeHog",
        "author": {
            "name": "Douglas Adams",
        },
        "genre": "Adventure",
    }
                        
    Huge Data Supoprt (~1TB) No. Why? yes
    Horizontal Scaling Does not support Horizontal scaling efficiently yes
    Tech Support Good, query-writing:simple Poor, query-writing:complex
    Schema Fixed Not fixed. We can have variable
    Use Cases - Schema Flexibility: Allows Flexible schema
    - Data Locality: Documents in a NoSQL database often stores all related information together. suitable case for Sharding
    - Horizontal Scaling Support: noSQL databases are designed to scale Horizontal