Blog

Software tips, techniques, and news.

NoSQL vs. Relational Databases

For decades, relational databases have been the go-to choice for developers. However, in recent years, relational databases have struggled with the workload that many applications now use day-to-day. Relational databases just don't have the flexibility and scalability required to deal with the amount of data. That's where NoSQL databases like Amazon DynamoDB shine. NoSQL databases are able to scale well to meet these requirements and allow for a less structured design.

Choosing between a NoSQL database like Amazon DynamoDB and a relational database will have lasting impacts on your project. Performance, ease of use, scalability, and more will all be impacted by the type of database you choose to use. It is an important decision when starting a new project. But what exactly are the differences between the two types, and how do you decide which one will suit your project best? 

youtube-preview

Major Differences

Flexibility

NoSQL allows you to be much more flexible with the structure of the database. A relational database requires a static structure and schema that must be defined at the start of the project. This can be nice when you need a structured schema, but becomes a problem if you need to make changes to the structure as it can be time-consuming and expensive. With NoSQL, you don't have these problems. Since there is no defined schema, it allows for more dynamic schemas. This makes it ideal for more complex projects that have constantly changing data structures.

Scalability

NoSQL is designed to scale horizontally whereas relational databases are designed to scale vertically. Vertical scaling means that in order to scale up, you have to upgrade the machine/server that hosts the database. This can be nice and easy, but if you are constantly scaling up, it can get very expensive. Horizontal scaling, on the other hand, involves adding more machines/servers to the resource pool. This is more cost-efficient since you can continue to add cheaper servers. This also allows for rapid growth with minimal downtime.

Querying

Relational databases query using the SQL language. Since SQL has been around for many years, it is well supported and documented. SQL is great when needing complex queries that require joins. NoSQL data can be queried quickly, but queries are more limited.


ACID vs. BASE

According to the CAP theorem, it is impossible to achieve both consistency and availability in a partition tolerant distributed system. ACID and BASE are database models that attempt to deal with the limitations of the CAP theorem in different ways. Relational databases use the ACID database model to have a consistent system. NoSQL databases use the BASE database model that focuses on high availability.

ACID (used by Relational databases)

  • Atomicity: Database transactions can be made in multiple statements and atomicity guarantees that each statement will either succeed or fail. If any statements in the transaction fail, it fails the whole transaction and doesn't change the database. This makes sure that the database has only valid and complete data.

  • Consistency: Ensures that any data being written to the database is valid and complies with all defined rules of the database.

  • Isolation: Since transactions are sometimes run concurrently, isolation ensures that each transaction will not affect any other transactions being executed.

  • Durability: Guarantees that once a transaction has successfully completed, it will stay that way even in the instance of something like a power failure.

BASE (used by NoSQL databases)

  • Basically Available: Instead of needing immediate consistency, BASE will ensure that data is available by replicating across the nodes in the database.

  • Soft State: Since there isn't immediate consistency in a BASE system, data values may change over time. BASE delegates the responsibility of consistency to the developers.

  • Eventually Consistent: BASE doesn't enforce data consistency, but it still can achieve it. It also allows for data reads even when it hasn't achieved consistency. 

When To Use NoSQL vs. Relational

So when exactly does it makes sense to use a NoSQL or a Relational database? These days it makes sense to use NoSQL databases in many cases. But there are still plenty of use cases when a relational database is the way to go. 

If you have large amounts of data or data types and need a flexible schema, you'll want to use a NoSQL database like Amazon DynamoDB as it allows for this flexibility. If you anticipate you'll need to scale your project up quickly and inexpensively, then a NoSQL database is the best option. 

If you need to use complex queries to get and format your data, consider using a relational database. You'll also want to use one if you're working with smaller amounts of data and don't expect that to change. SQL and relational databases are much more structured and using NoSQL in this instance would be overkill. You will also want to take into account that since relational databases and SQL have been around for many years, they are more supported and stable, and there are larger communities for support and help.


If you have questions about the differences between NoSQL and Relational databases or you want to know which one to use for your project, contact DB Services and let's talk about what we can accomplish together. 

Quinn O'Connor headshot.
Quinn O'Connor

Quinn is a methodical and supportive application developer who is always up for a challenge. He is passionate about helping clients reach their goals and providing the best experience possible for them. His humble approach to teamwork and consistent nature make him a reliable team member and resource for clients.