> For the complete documentation index, see [llms.txt](https://aaronice.gitbook.io/system-design/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aaronice.gitbook.io/system-design/distributed-systems/sql-vs-nosql.md).

# SQL vs. NoSQL

SQL and NoSQL - or relational databases and non-relational databases.

## SQL

Relational databases are structured and have predefined schemas.

Relational databases store data in rows and columns.

## NoSQL

Non-relational databases are unstructured, distributed and have a dynamic schema

### Most common types of NoSQL

**Key-Value Stores**: Data is stored in an array of key-value pairs.

e.g. Redis, Voldemort and Dynamo

**Document Databases**: In these databases data is stored in documents

e.g. CouchDB, MongoDB

**Wide-Column Databases**: Instead of ‘tables,’ in columnar databases we have column families, which are containers for rows. (Unlike relational databases, we don’t need to know all the columns up front, and each row doesn’t have to have the same number of columns.)

e.g. Cassandra and HBase.

**Graph Databases**: These databases are used to store data whose relations are best represented in a graph.

e.g. Neo4J and InfiniteGraph

## High Level Differences between SQL and NoSQL

**Storage**\
SQL - stores data in tables\
NoSQL - different data storage models, such as KV-store, document, graph, columnar

**Schema**\
SQL - fixed schema, column must be decided; alter schema involves modifying the whole database\
NoSQL - schemas are dynamic

**Querying**\
SQL - SQL (structured query language)\
NoSQL - Unstructured query language, different databases, different syntax

**Scalability**\
SQL - most commonly, vertically scalable (increasing horsepower of hardware); harder to scale Relational DB across multiple servers\
NoSQL - horizontally scalable; adding more servers; many NoSQL DB also distribute data automatically

**Reliability or ACID Compliancy (Atomicity, Consistency, Isolation, Durability)**

SQL - vast majority of relational databases are ACID compliant\
NoSQL - most NoSQL solutions sacrifice ACID compliance for performance and scalability

## Which one to use?

### Reasons to use SQL database

* We need to ensure ACID compliance.
* Your data is structured and unchanging.

e.g. e-commerce and financial applications

### Reasons to use NoSQL database

* Storing large volumes of data that often have little to no structure.&#x20;
* Making the most of cloud computing and storage.&#x20;
* Rapid development.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://aaronice.gitbook.io/system-design/distributed-systems/sql-vs-nosql.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
