Tiyaze Resource Hub — v1.0
Lesson 02 ~30 min read

Types of Databases

Not every database works the same way. The model a database uses determines how it stores data, how you query it, and what kinds of problems it solves best. Choosing the wrong type is a costly mistake.

Not All Databases Are Alike

A database is defined by its model — the way it organises and structures data internally. Different models are better suited to different problems. Choosing the wrong model for your data is one of the most expensive architectural mistakes a developer can make.

There are four major database models in widespread use today, each with a clear philosophy, strengths, and weaknesses.

1. Relational Databases

The dominant model since the 1970s. Data is organised into tables (rows and columns), and tables relate to each other through shared keys. Based on solid mathematical foundations (relational algebra, set theory). Queried using SQL.

relational model
Students Table
┌────────────┬─────────────┬─────┐
│ student_id │ name        │ age │
├────────────┼─────────────┼─────┤
│ cen/01     │ Kondwani    │ 21  │
│ ict/02     │ Chisomo     │ 23  │
└────────────┴─────────────┴─────┘

Enrolments Table — links via student_id
┌────────────────┬────────────┬─────────────────    ┐
│ enrolment_id │ student_id │ course              │
├──────────────┼────────────┼─────────────────────────┤
│ 101          │ cen/01     │ Web Development     │
│ 102          │ cen/01     │ Spiritual formation │
│ 103          │ ict/02     │ Trigonometry        │
└──────────────┴────────────┴─────────────────    ┘
Examples
MySQL, PostgreSQL, SQLite, Microsoft SQL Server, Oracle Database
Best for
Structured data with clear relationships — banking, ERP, student records, e-commerce
Strengths
ACID compliance, powerful querying, mature tooling, industry standard
Limitations
Less flexible with unstructured or rapidly changing data; scaling horizontally is complex

2. Document Databases (NoSQL)

Store data as documents — typically JSON or BSON format. Each document is self-contained and can have its own structure. No rigid schema required. Excellent for flexible, hierarchical data.

document model (JSON)
// Each student is a self-contained document
{
  "_id": "cen/01",
  "name": "Kondwani",
  "age": 21,
  "courses": ["Computer Architecture", "C++"],
  "address": {
    "city": "Mzuzu",
    "country": "Malawi"
  }
}
Examples
MongoDB, CouchDB, Firebase Firestore, Amazon DynamoDB
Best for
Content management, user profiles, catalogues, real-time apps
Strengths
Flexible schema, fast for hierarchical data, easy horizontal scaling
Limitations
Weaker support for complex joins; ACID guarantees vary by system

3. Key-Value Stores

The simplest model — data stored as pairs of a unique key and a value. Extremely fast for lookups. Used primarily for caching and session management.

key-value model
session:user_42{ name: "Kondwani", role: "student" }
cache:homepage"<html>...cached HTML...</html>"
counter:page_views18472
token:abc123def{ user_id: 42, expires: 1720000000 }
Examples
Redis, Amazon DynamoDB, Memcached, Riak
Best for
Session storage, caching, leaderboards, real-time counters

4. Graph Databases

Store data as nodes (entities) and edges (relationships). Designed for highly connected data where the relationships themselves are as important as the data.

graph model
Nodes (entities) and Edges (relationships)

(Kondwani)  -[ENROLLED_IN]→ (Web Development)
(Kondwani)  -[FRIENDS_WITH]→ (Chisomo)
(Chisomo)  -[ENROLLED_IN]→ (Networks)
(Web Development)  -[TAUGHT_BY]→ (Mr Phiri)
Examples
Neo4j, Amazon Neptune, ArangoDB
Best for
Social networks, recommendation engines, fraud detection, knowledge graphs
// SQL vs NoSQL

Relational databases are commonly referred to as SQL databases because they use the Structured Query Language (SQL) to manage and query data. Other modern database models such as document, key-value, and graph databases are often grouped under the term NoSQL. Originally meaning "No SQL", the term is now widely interpreted as "Not Only SQL", indicating that these systems do not rely solely on the relational model. The best choice depends on the structure of your data, scalability needs, and the problem you are trying to solve.

// Knowledge Check
A social network needs to map connections between millions of users — who follows whom, who is friends with whom. Which database type is most naturally suited to this problem?