SQL Vs No-SQL

  • Relational databases store data in table – rows and columns.
  • Each row contains all the information about one entity and each column contains all the separate data points. Some of the most popular relational databases are MySQL, Oracle, MS SQL Server, SQLite, Postgres, and MariaDB.
  • Non-relational databases are unstructured and have a dynamic schema. Example a book record. Each book can have any kind of attributes like “book 1” will only have ISBN, Book Title, Edition Number, Author Name as attributes. Book 2 can have all the attributes which book 1 had and additional attributes like rating, publisher name etc.
  • It is particularly useful for storing unstructured data, where the structure keeps changing and does not fit the relational schemas

Common types of No-SQL

  • Key-Value Stores
    • Data is stored as a collection of key-value pairs in which a key serves as a unique identifier.
    • Stored values can be any type of binary object (text, video, JSON document, etc.) and are accessed via a key
    • Data is partitioned and replicated across a cluster to get scalability and availability.For this reason, key value stores often do not support transactions.
    • Example: customized recommendations for a user. user session details.
    • Well-known key-value stores include Redis, Voldemort, and Dynamo.
    • Highly effective at scaling applications that deal with high-velocity, non-transactional data.
    • Key value stores have no default query language. You retrieve data using get, put, and delete commands. This is the reason it has high performance.
  • Document Databases
    • Data is stored in documents (instead of rows and columns in a table) and these documents are grouped together in collections.
    • Similar to key-value stores, but in this case, a value is a single document that stores all data related to a specific key.
    • Document databases typically store self-describing JSON, XML, and BSON documents.
    • Popular fields in the document can be indexed to provide fast retrieval without knowing the key.
    • Each document can have an entirely different structure.
    • Document databases include the CouchDB and MongoDB
    • The document model works well with use cases such as catalogs, user profiles, and content management systems where each document is unique and evolves over time.
    • Document databases enable flexible indexing, powerful ad hoc queries, and analytics over collections of documents.
  • Wide-Column Databases
    • Stores data in tables with rows and columns similar to RDBMS, but names and formats of columns can vary from row to row across the table.
    • Wide Column database allows us to not know all the columns up front and each row can have different columns
    • By using columns you can gain much greater speed when querying data.
    • The most significant benefit of having column-oriented databases is that you can store large amounts of data within a single column.
    • This feature allows you to reduce disk resources and the time it takes to retrieve information from it.
    • It is best suited for analyzing large datasets.
    • Wide-Column Databases : Cassandra and HBase
    • Suited for data warehouses and CRM systems
  • Graph Databases
    • Nodes and relationships are the bases of graph databases.
    • A node represents an entity, like a vehicle, user, product. A relationship represents how two nodes are associated.
    • Graph databases use nodes that contain lists of relationship records. These records represent relationships with other nodes, which eliminates the (time-consuming) search-match operation found in relational databases.
    • It uses graph structures to store, map, and query relationships.
    • They provide index-free adjacency, so that adjacent elements are linked together without using an index.
    • Examples of graph database include Neo4J and InfiniteGraph.
    • Walmart uses Neo4j to provide customers personalized, relevant product recommendations and promotions

Key differences between SQL and NoSQL 

Use cases where SQL is ideal

  • Data requirements or structure can be identified up-front
  • Data integrity is essential
  • Business is not experiencing massive change

Use cases where NoSQL is ideal

  • Data Requirements are evolving
  • Not concerned about data consistency and 100% data integrity is not your top goal.
  • Priority is easy scalability and availability

Thanks. Share your comments / feedback.

One thought on “SQL Vs No-SQL

Leave a Reply