Get this book -> Problems on Array: For Interviews and Competitive Programming
In the previous article, I had covered the different types of databases. Before reading this, please go through the previous article here. This will give you a complete overview of databases and different types.
In this article, we will gather knowledge about different NoSQL databases and choosing the correct database for a given problem or use case.
The different types are:
- Key-Value Databases
- Document Databases
- Graph Databases
- Columnar Databases
The different examples of NoSQL Databases are:
NoSQL refers to non-SQL or non-relational databases that do not store the data in standard tabular form.NoSQL database can handle a large amount of data in a much faster way than RDBMS.NoSQL database can scale easily.
Some Of the Resounding Features of NoSQL
Dynamic Schemas - In relational databases, we have to define the scheme first before inserting the data defining the relationship between the tables making things more difficult because you have to change the schema every time the requirements change. But in a non-relational database, we don’t need to do this.
Scalability - NoSQL database can be scalable depending on a large amount of data. In the NoSQL database, a horizontal sharding feature is available.
Replication - the automatic database replication to maintain availability.
Integrated Caching - Most NoSQL database comes with a caching mechanism that can be used to keep the most recent data.
Before, Choosing any database we have to consider the three most important properties:-
- Consistency: See current data regardless of updates and deletes
- Availability: Every request must receive a non-error response from the database.
- Partition Tolerance: System continues to operate as expected despite network or message failures.
It is stated that, in the case of a distributed system, it is impossible to guarantee all the three properties
This is CAP theorem suggested by Computer Scientist Eric Barker
Here, I have explained about different types of NoSQL databases
The Different NoSQL databases available falls into a different category
Cassandra, HBase, Kudu’
Let see, Some of the databases in detail and their best use cases: -
Redis comes under the key-value database category that means it can store the data in key-value pairs. Redis is written in C.
- Support the different kinds of data structures like Bit and bitfield operations (for example to implement bloom filters), sets (also union/diff/inter), lists (also a queue;), hashes (objects of multiple fields), Sorted sets.
- Can be used to store the cache.
- Supports Master-slave replication, automatic failover.
Best fit for rapidly changing data
Real-Life Use Case: - To store real-time stock prices. Real-time analytics. Leaderboards. Real-time communication
MongoDB comes under the document database category,
- it can store the data in the JSON format.MongoDB is written in C++.
- Strong query features available like RDBMS.
- Built-in sharding feature available.
- MongoDB has geospatial indexing.
Best fit when we need the dynamic queries & to define indexes
Real-Life Use Case : Content Management System, Operational Intelligence Product data management
Cassandra comes under the columnar database.
- Cassandra is written in Java. License by Apache.
- It is highly scalable and has no single point of failure.
- Cassandra support ACID properties (Atomicity, Consistency, Integrity & Durability).
- It supports all possible formats of data(structured,semi-structured, and unstructured).
- It supports fast writes and can store hundreds of terabytes of data without affecting the read efficiency.
Best fit when we need to store the huge amount of data that doesn't fit on the server.
Real-Life Use Case: Data collection from huge sensor arrays Web analytics, to count hits by the hour, by browser, by IP
HBase comes under the columnar database.License by Apache.
- Apache HBase is the Hadoop database, a distributed, scalable, big data store.
- Realtime and random update/read access on big data.
- It is modeled after Google's BigTable.
- It's strictly consistent with read and writes access to data.
- Automatic and configurable sharding of tables
- Product of Facebook.Facebook uses this database to store billions of structured and semi-structured data.
Best Fit when we need real-time and random read/write access to huge volumes of data (Big data)
Real-Life Use Case : Search engines. Analyzing log data.
Neo4j is a graph database.Neo4j is written in Java. Licence under GPL-3.
It is open-source.
- It supports Indexes by using Apache Lucence
- It supports UNIQUE constraints.
- It supports full ACID(Atomicity, Consistency, Isolation, and Durability) rules.
- Neo4j is an easy and faster way to retrieve/traversal of the data.
Best fit for using in social network application
Real-Life Use Case:
Use in road maps, searching routes in social relations.
Other not so popular NoSQL databases are: -Couchbase,VoltDB,Scalaris RethinkDB
So, Now we will wrap up, So in this article, we have covered different NoSQL databases and their use cases and About the cap theorem.