NoSQL ("not only SQL") databases store data in ways other than relational tables. They became popular because modern applications handle huge, varied data and many users.
Why NoSQL
Relational databases work very well for structured data and strong consistency. They struggle when data is huge, changes shape often or must be spread over many cheap servers. NoSQL systems trade some relational features for flexibility and scale.
NoSQL data models
| Model | Idea | Example product | Typical use |
|---|---|---|---|
| Document | JSON-like documents in collections | MongoDB | Catalogues, profiles, content |
| Key-value | A key maps to a value | Redis | Caching, sessions |
| Column family | Rows with flexible column groups | Cassandra | Logs, time series |
| Graph | Nodes and edges | Neo4j | Social networks, recommendations |
Document databases: uses and features
- No fixed schema: two documents in a collection can have different fields.
- Nested data (arrays and sub-documents) in one document, so fewer joins.
- Easy to scale out by spreading data over servers (sharding).
- Fits JSON data used by web and mobile apps.
{
"name": "Ravi",
"city": "Delhi",
"courses": ["DBMS", "Java"],
"address": { "pin": "110001" }
}
CAP theorem
A distributed database cannot guarantee all three of these at once:
- Consistency: every read sees the latest write.
- Availability: every request gets a response.
- Partition tolerance: the system works even if the network splits.
Since network partitions will happen, a design must pick between consistency and availability during a partition.
BASE versus ACID
| ACID (relational) | BASE (many NoSQL) |
|---|---|
| Atomic, consistent, isolated, durable | Basically Available, Soft state, Eventually consistent |
| Strong correctness | High availability and speed |
| Bank transfers | Likes counter, feed |
Eventually consistent means replicas may differ for a short time but converge.
Common mistakes
- Treating NoSQL as "better than SQL". It is a different trade-off.
- Thinking schema-less means no design. The application still needs a data design.
Practice questions
- What is NoSQL? Why was it developed?
- Name four NoSQL data models with one example each.
- State the CAP theorem.
- Compare ACID and BASE.
- List three features of document databases.
Answers to the practice questions
- A group of non-relational databases built for scale and flexible data.
- Document (MongoDB), key-value (Redis), column family (Cassandra), graph (Neo4j).
- A distributed system cannot give consistency, availability and partition tolerance all at once.
- ACID gives strict correctness; BASE gives availability and eventual consistency.
- Flexible schema, nested data, easy scaling.
Sources
- Official BCA syllabus Database Management Systems, course code CC202, Unit IV
- Raghu Ramakrishnan and Johannes Gehrke, Database Management Systems, 3rd edition, McGraw-Hill
