Dung (Donny) Nguyen

Senior Software Engineer

Relational and Non-Relational Databases

Choosing how to store your data is one of the most important decisions in software design. At the highest level, databases fall into two broad families: relational (SQL) and non-relational (NoSQL). Understanding how they differ — and when to use each — is a foundational skill for any developer.


What Is a Relational Database?

A relational database stores data in tables made up of rows and columns, following the relational model introduced by E. F. Codd in 1970. Each table represents an entity (such as users or orders), each row is a single record, and each column is an attribute of that record.

Tables are connected through keys:

You interact with relational databases using SQL (Structured Query Language), a powerful, standardized language for defining schemas and querying data.

Example

Imagine an online store with two tables:

users

id name email
1 Alice alice@example.com
2 Bob bob@example.com

orders

id user_id total
10 1 49.99
11 2 19.95

The user_id column in orders is a foreign key pointing to users.id. To find every order placed by Alice, you join the two tables:

SELECT o.id, o.total
FROM orders o
JOIN users u ON o.user_id = u.id
WHERE u.name = 'Alice';

Key Characteristics


What Is a Non-Relational Database?

A non-relational database (commonly called NoSQL, meaning “not only SQL”) stores data in formats other than traditional tables. Instead of enforcing a rigid schema, NoSQL databases embrace flexibility, scalability, and specialized data models.

NoSQL databases generally fall into four main types:

1. Document Stores

Data is stored as self-contained documents, typically in JSON or BSON. Each document can have its own structure, making them ideal for evolving or semi-structured data.

{
  "id": 1,
  "name": "Alice",
  "email": "alice@example.com",
  "orders": [
    { "id": 10, "total": 49.99 },
    { "id": 12, "total": 12.50 }
  ]
}

Notice that a user’s orders are embedded directly in the document — no join required. Example: MongoDB, Couchbase.

2. Key-Value Stores

The simplest model: every item is a key mapped to a value. Extremely fast for lookups, caching, and session storage. Example: Redis, Amazon DynamoDB.

"session:abc123" -> { "userId": 1, "expires": "2026-08-28T12:00:00Z" }

3. Column-Family Stores

Data is stored in columns grouped into families, optimized for huge volumes and write-heavy workloads across distributed clusters. Example: Apache Cassandra, HBase.

4. Graph Databases

Data is modeled as nodes (entities) and edges (relationships), ideal for highly connected data like social networks, recommendation engines, and fraud detection. Example: Neo4j, Amazon Neptune.

5. Vector Databases

A newer category built for AI: they store vector embeddings and support similarity search for semantic and recommendation use cases. Example: Pinecone, Milvus.

Key Characteristics


Relational vs. Non-Relational: Side by Side

Aspect Relational (SQL) Non-Relational (NoSQL)
Data model Tables with rows and columns Documents, key-value, column-family, graph
Schema Fixed, defined upfront Flexible, dynamic
Query language SQL (standardized) Varies by database
Relationships Joins via foreign keys Embedding, references, or graph edges
Transactions Strong ACID guarantees Often BASE; ACID varies by product
Scaling Primarily vertical (scale up) Primarily horizontal (scale out)
Best for Structured data, complex queries Large-scale, evolving, or specialized data

The CAP Theorem

When data is distributed across multiple servers, the CAP theorem states you can only fully guarantee two of these three properties at once:

Relational databases traditionally prioritize consistency, while many NoSQL databases lean toward availability and partition tolerance. Understanding this trade-off helps explain the design choices behind each system.


When to Use Which

Choose a relational database when:

Choose a non-relational database when:


Polyglot Persistence

In practice, you don’t have to pick just one. Modern applications often use polyglot persistence — combining multiple databases, each suited to a specific job. For example:

The goal is to use the right tool for each part of your system.


Conclusion

Relational databases offer structure, consistency, and powerful querying through SQL, making them the backbone of countless applications. Non-relational databases trade rigid structure for flexibility and scalability, excelling at large-scale, evolving, or specialized workloads. Neither is universally “better” — the right choice depends on your data, your access patterns, and your requirements. Mastering both, and knowing when to combine them, is what makes you an effective database engineer.