As a Java developer, we can’t develop an insightful application without the use of a database software. Traditionally, we use a relational database to work with an application. Of course, a relational database is a structured database and contains multiple tables to maintain meaningful relations between them. Additionally, it uses SQL like queries to operate with data stored in the tables.
In contrast, suppose we have to work with a large amount of unstructured data which is not advantageous to store in the form of tables, keeping other factors in mind as well, then how will we store our data? The simple answer is ‘we should use NoSQL database’ in that case. Further, you might even have some other questions in your mind about NoSQL type databases. Of course, our topic on ‘Types Of NoSQL Databases and Examples’ will answer all your questions in a while.
In order to have a clear understanding on NoSQL databases, you just need to go through this article step by step. Let’s start learning a new hot topic ‘Types Of NoSQL Databases and Examples’ and its related concepts accordingly.
Table of Contents (Click on links below to navigate)
- 1 What will you expect from this Article?
- 2 What is NoSQL Database?
- 3 What is SQL database?
- 4 Why do we need a NoSQL Database?
- 5 What are some popular examples of NoSQL databases?
- 6 How many types of NoSQL Databases and Examples?
- 7 When to use Which type of NoSQL Database?
- 8 What are the features of NoSQL Databases?
- 9 What are the benefits of using a NoSQL Database?
- 10 What are the Disadvantages of a NoSQL Database?
- 11 When to use a NoSQL Database?
- 12 What is the difference between SQL and NoSQL databases?
- 13 How to work in Spring Boot with NoSQL databases?
What will you expect from this Article?
1) What is the NoSQL database? What is the SQL database?
2) What are the examples of some popular NoSQL Databases?
3) Additionally, How many types of NoSQL databases are there with examples?
4) When to use Which type of NoSQL database?
5) Why do we need a NoSQL database?
6) Equally importantly, What are the benefits and drawbacks of using NoSQL databases?
7) When to use a NoSQL database?
8) What are the differences between SQL and NoSQL databases?
9) How to work with NoSQL databases in Spring Boot?
What is NoSQL Database?
NoSQL is a substantial term to specify any alternative system to traditional SQL databases.
NoSQL databases are those who store data in a format other than relational tables. These databases can also store relational data, but they just store it differently than relational databases do.
SQL data models allow relations by joining tables. On the other hand, NoSQL data models allow related data to be nested within a single data structure. Some people in the industry say the term “NoSQL” stands for “non SQL” while others say it stands for “not only SQL”.
NoSQL databases are all entirely different from SQL type databases. They use a data model that has a different structure than the typical row-and-column table model used with relational database management systems (RDBMS). Furthermore, NoSQL databases are all absolutely different from each other, as well.
What is SQL database?
The term ‘SQL’ represents Structured Query Language. A SQL database is a collection of tables that stores a specific set of structured data. Each table contains the rows & columns to accommodate the structured data. The alternative term of SQL database is the relational database. The SQL (relational) databases rely on SQL as the engine that allows us to perform all the database operations such as create, retrieve, update, and delete. Simply put, SQL is the essential programming language for all relational database management systems (RDBMS). That’s why people in the industry call them SQL databases.
Examples: MySQL, PostgreSQL, MariaDB, SQL Server, H2DB, Sybase, Oracle etc.
Why do we need a NoSQL Database?
This question also answers one more question, which is ‘What are the major issues in using SQL databases?’. In fact, NoSQL databases were invented after the disability of SQL databases to deal with the demand of web-scale applications that managed huge amounts of data and traffic. Almost every company is finding a way to use a NoSQL technology in order to serve an increasing list of use cases and also saving money and development efforts. The popularity of a NoSQL database is getting increased day by day because of the following reasons.
1) The speed of development with NoSQL databases can be much faster than with a SQL database.
2) SQL database can’t serve the volume of data in many applications at lower prices than a NoSQL database.
3) NoSQL database can handle the structure of multiple forms of data more easily.
4) SQL databases can’t handle the scale of traffic and the need for zero downtime.
What are some popular examples of NoSQL databases?
Some examples of popular NoSQL databases are MongoDB, CouchDB, CouchBase, Cassandra, HBase, Redis, Riak, Neo4J.
MongoDB, CouchDB, CouchBase are document-oriented NoSQL databases.
Redis and Riak are key-value databases.
Cassandra and HBase are column family stores.
Neo4J is a graph database.
How many types of NoSQL Databases and Examples?
NoSQL databases come in a variety of types based on their data model.
Key-Value Databases, Wide-column Stores, Document Databases, Graph Databases are the types of NoSQL Databases.
The Key-Value databases are simplest and easiest to implement. They internally use a hash table where there is a unique key and a pointer to a particular item of data. Key-value databases are great for use cases where you need to store large amounts of data, but you don’t need to perform complex queries to retrieve it.
Examples: Tokyo Cabinet/Tyrant, Redis, DynanoDB, Voldemort, Oracle BDB, Amazon SimpleDB, Riak.
Use cases: Shopping carts, User preferences, and User profiles.
Wide-column Stores (Column-oriented databases)
They store data in tables, rows, and dynamic columns. Here each row doesn’t need to have the same columns. Therefore, they are better than relational databases in flexibility. Also, these were created to store and process very large amounts of data distributed over many machines. Wide-column stores are suitable for storing Internet of Things data and user profile data.
Examples: Cassandra, HBase, BigTable, Hypertable
Use cases: Analytics
They are similar to key-value stores and inspired by Lotus Notes. Document Databases store data in documents like JSON objects. Further JSON can store values in a variety of types like Strings, Numbers, Booleans, Arrays or Objects. They also support powerful query languages. Hence, they can be used as a general purpose database. According to DB-engines ranking, MongoDB is consistently ranked as the world’s most popular NoSQL database.
Examples: MongoDB, CouchDB, OrientDB, RavenDB
Use cases: Trading platforms, E-commerce platforms, and Mobile app development.
They use a flexible graph model which, again, can scale across multiple machines. Graph Databases store data in nodes and edges. Nodes typically store information about people, places, and things while edges store information about the relationships between the nodes. They are useful in use cases where you need to traverse relationships to look for patterns such as social networks, fraud detection, and recommendation engines.
Examples: Neo4J, JanusGraph, InfoGrid, Infinite Graph, Flock DB
Use cases: Social networks, Fraud detection, and Knowledge graphs.
When to use Which type of NoSQL Database?
NoSQL databases are generally better suited to store and model all types of data, such as structured, semi-structured, and unstructured data in one database. Furthermore, since the data we store in a NoSQL database does not need a pre-established schema as is the case with a SQL database, NoSQL databases are extremely flexible. Since each one of NoSQL databases has a specific characteristic, sometimes it becomes a tough task to decide which type is relevant to a particular use case. Hence, we should have some idea on common use cases in order to take a decision while selecting a database.
When to use a key-value database?
1) When Using Cache accelerates the application performance
2) Storing personal data about specific users
3) Managing each player’s session in massive multiplayer online games
4) Real-time random data access, e.g., user session attributes in an online application such as gaming or finance
5) Session Management on a high importance
When to use a document database?
1) Mobile apps
2) Payment Processing
3) Product catalogs and content management
4) Internet of Things (IoT) and time-series data
5) Customer data management and personalization
6) Operational analytics & Realtime Analytics
When to use a column-oriented database?
1) Data warehousing
2) Analytics & Reporting
3) Big Data Processing
When to use a graph database?
1) Social Media
2) Fraud Detection
3) Realtime Recommendations
4) Network and IT operations
What are the features of NoSQL Databases?
Although each NoSQL database has its own special features, but at a high level majority of NoSQL databases have the following features.
1) Flexible schemas: We don’t need to determine and declare a table’s schema before inserting data.
2) Horizontal scaling: NoSQL databases have a variety of scaling choices available. In the past, database scaling has been a primary concern for large applications and options have been either restricted in number or expensive to implement.
3) Fast queries due to the data model: Data model in NoSQL database ensures fast execution of queries.
4) Ease of use for developers: Multiple surveys indicate that the NoSQL databases are easy to use.
What are the benefits of using a NoSQL Database?
NoSQL databases are more flexible and scalable, faster, reliable, distributed, schema-free architecture, easy replication support, simple API, support for big data etc.
NoSQL databases can often perform better than SQL(relational databases) for your use case. For example, if you’re using a document database and are storing all the information about an object in the same document (so that it matches the objects in your code), the database only needs to go to one place for those queries. In a SQL database, the same query would likely involve joining multiple tables and records, which can dramatically impact performance.
Generally, NoSQL databases have very flexible schemas. A flexible schema offers us to smoothly make adjustments to our database whenever requirements change. We can iterate rapidly and continually incorporate new application features to offer value to our users faster.
Most of the NoSQL databases allow us to scale-out horizontally. It means we can add less expensive servers at any time we need to. In contrast, most SQL databases (relational databases) require you to scale-up vertically. It means we need to migrate to a larger, more expensive server when we exceed the capacity standard of the current server.
Data in SQL databases is usually normalized. Therefore, queries for a single object or entity need to join data from multiple tables. As our tables grow in size, the joins can become costly. However, data in NoSQL databases is generally stored in a way that is already optimized for queries. Hence, queries in NoSQL databases can be faster than SQL type databases.
Some of the NoSQL databases map their data structures to those of popular programming languages. One of the best example in this category is the MongoDB that maps its data structure well with the Java programming language. Furthermore, this mapping allows developers to store their data in the similar manner as they use it in their application code. Additionally, this mapping can offer developers to write comparatively less code, and also reduces development time and future bugs.
What are the Disadvantages of a NoSQL Database?
One of the recognized disadvantages of NoSQL databases is that they don’t support ACID (atomicity, consistency, isolation, durability) transactions across multiple documents. Single record atomicity is possible for lots of applications with appropriate schema design. However, there are still many applications that may demand ACID across multiple records. Further, MongoDB included support for multi-document ACID transactions in the 4.0 release to address this drawback.
As NoSQL data models primarily focused on optimizing for queries rather than reducing data duplication, therefore NoSQL databases can be larger than SQL databases. However, this can’t be considered as a major drawback because storage is currently not too expensive. Even some NoSQL databases also support compression mechanism to reduce the data size.
NoSQL databases do not provide the same level of data consistency as the SQL databases. At times when data is not consistent, it means they are not convenient for transactions that require immediate integrity, such as banking and ATM transactions.
When to use a NoSQL Database?
In the late 1990s, almost every type of applications were based on SQL type databases. But the rise of Internet has changed everything in the context of application development. These changes have influenced many organizations of all sizes to adopt a new database technology called NoSQL. Below are some of the facts when we should consider using a NoSQL databases.
1) If you want a faster development
2) If you want structured and semi-structured data storage
3) If you have a requirement of scale-out architecture
4) If you want to handle huge amount of data
5) If your application is using microservices and real-time streaming
What is the difference between SQL and NoSQL databases?
Let’s discuss about the differences between the SQL databases and NoSQL databases based on some criteria.
The primary focus of SQL database is to reduce data duplication. NoSQL databases have focused on scaling and offering for rapid application change driven by agile and DevOps practices.
Data Storage Pattern
SQL databases follow tabular structure with fixed rows and columns. NoSQL databases have multiple structures based on the type of NoSQL database such as JSON, key-value pairs, wide-column, table with rows and dynamic columns, nodes and edges etc.
SQL database supports vertical scaling, whereas NoSQL databases support horizontal scaling.
Multi-Record ACID Transactions
SQL databases support multi-record ACID transactions. Most of the NoSQL databases don’t support multi-record ACID transactions except some of them such as MongoDB.
SQL databases have rigid schemas, whereas NoSQL databases have flexible schemas.
While querying some records from the database, SQL databases take help of joins to prepare the results. NoSQL databases don’t take help of joins.
To protect the integrity of data while performing various database operations by applications and users, NoSQL and SQL databases follow different approaches. Most NoSQL database systems manage data integrity with an approach known as BASE (Basically Available, Soft State with Eventual Consistency). On the other hand, SQL databases follow the ACID (Atomicity, Consistency, Isolation and Durability) approach.
SQL databases require ORM while working with programming languages like Java. Many of the NoSQL databases don’t require ORM. However, MongoDB documents map directly to data structures in most popular programming languages.
How to work in Spring Boot with NoSQL databases?
We have separate articles with hands-on examples of working with NoSQL databases in Spring Boot. Below are some of the links.