NoSQL stands for “Not Only SQL”. It refers to a class of non-relational database systems designed to handle:
- Large volumes of unstructured or semi-structured data
- Horizontal scalability
- Flexible data models
NoSQL is widely used in applications like social networks, IoT, real-time analytics, and big data systems.
Types of NoSQL Databases
Type | Description | Example |
---|---|---|
Document-based | Stores data as JSON-like documents | MongoDB, CouchDB |
Key-Value | Data stored as key-value pairs | Redis, DynamoDB |
Column-family | Stores data in column-based format | Cassandra, HBase |
Graph-based | Focuses on relationships using graphs | Neo4j, ArangoDB |
Advantages of NoSQL
- Schema-less (flexible structure)
- High performance on large datasets
- Easy to scale horizontally (add more machines)
- Ideal for real-time, distributed applications
CAP Theorem (Brewer’s Theorem)
The CAP theorem describes the trade-offs in a distributed system involving three guarantees:
1. Consistency (C)
Every read gets the most recent write (no stale data).
Equivalent to having a single up-to-date copy of the data.
2. Availability (A)
The system is always responsive — every request gets a (non-error) response, even if it’s not the latest.
3. Partition Tolerance (P)
The system continues to function even when network partitions (communication breaks between nodes) occur.
CAP Theorem Statement:
In a distributed system, it is impossible to simultaneously guarantee all three: Consistency, Availability, and Partition Tolerance.
You can only choose two out of three.
CAP Trade-off Scenarios
Type | Guarantees | Compromises | Example |
---|---|---|---|
CP System | Consistency + Partition Tolerance | May not always be available | MongoDB (replica sets) |
AP System | Availability + Partition Tolerance | May return stale data (no consistency) | Cassandra, DynamoDB |
CA System | Consistency + Availability | Not fault-tolerant (no partition tolerance) | Rare in practice |
In real distributed systems, Partition Tolerance is a must, so the real choice is between C vs A.
Conclusion
- NoSQL databases often sacrifice Consistency to gain Availability and Partition Tolerance, especially in large, distributed systems.
- The CAP theorem helps designers choose the right database based on application needs.