DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Databases
  4. NoSQL vs Relational Databases: When to Use What

NoSQL vs Relational Databases: When to Use What

Read on in order to discover the differences between NoSQL and relational databases and also how NoSQL databases scale horizontally.

Rajat Mehta user avatar by
Rajat Mehta
·
May. 18, 18 · Opinion
Like (4)
Save
Tweet
Share
24.55K Views

Join the DZone community and get the full member experience.

Join For Free

Relational databases have existed for more than 40 years now, and they work well. There are specific use cases, however, where a software professional might use a NoSQL database over a relational one. Some of those reasons are:

  • Relational databases are highly available and highly consistent. Thereby running atomic operations on them is a piece of cake and they run very well (i.e. database transactions run very well on relational databases). Hence, if you are looking for normal CRUD operation type websites, a relational database is still a solid option to choose.
  • CAP theorem stands for C – Consistency, A — Availability, P — Partitioning (or Scalability) and states that having all three properties at the same time is not possible, so at the best, you can get two properties from these and not the third one. Relational databases provide consistency and availability but lack solid partitioning functionality, even though relational databases support partitioning, but due to the core concept of ‘Joins’ and other things like shared indexes, scaling them using partitions is very difficult and not optimal.
  • The point mentioned above is the key reason for the existence of NoSQL databases like MongoDB or Cassandra. These databases provide excellent support for horizontal scalability. They do lack a bit on the principle of consistency as most of them don't support distributed transactions (or as perfectly as a relational database does). They also don't have joins exactly like relational databases, and these are the key reasons why they scale so well horizontally (i.e. by adding more machines horizontally).
  • Another reason for the usage of NoSQL databases is their developer friendliness. DB’s like MongoDB are document databases where the data is stored as a JSON, which is highly compatible with most web user interfaces (read ‘Single page Java Apps’) and has excellent tooling support.
  • Relational databases have a strict schema for the data storage. Through the use of 'alter' statements, the schema can be changed, but it has its impact on the existing code ('application specific code'), which has to be changed in accordance with the changes made to the schema. The NoSQL databases, on the other hand, support easy schema changes on the fly without affecting any existing code.

How Do NoSQL Databases Scale Horizontally?

There are 2 key approaches:

  1. Auto-Sharding: This is what is followed by Google's Bigtable. It basically assigns a range of values to a partition (this is one approach for partitioning). So when a certain value falls within a certain range, the database knows which partition to look in. It is somewhat similar to a hashtable bucketing concept.
  2. Consistent Hashing: The other approach is consistent hashing, which is followed by DynamoDB in Amazon. It prepares a hash of machines in a circular fashion, and if a certain machine fails in the circle, the database knows where to look for the next record in this circle of machines.
Database Relational database NoSQL

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Mr. Over, the Engineer [Comic]
  • Microservices Discovery With Eureka
  • Express Hibernate Queries as Type-Safe Java Streams
  • AWS Cloud Migration: Best Practices and Pitfalls to Avoid

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: