Chapter 2: Types of Databases — The Landscape

Not all data is the same, and not all access patterns are the same. Different database types optimize for different workloads. This chapter maps the entire landscape so you know what exists and when each type shines.

The Big Categories

DATABASES │ ┌────────────────┼────────────────┐ │ │ │ Relational NoSQL Specialized (SQL) │ │ │ ├── Key-Value ├── Time-Series ├── PostgreSQL ├── Document ├── Search Engine ├── MySQL ├── Column-Family├── Graph ├── Oracle ├── Graph ├── Vector ├── SQL Server │ ├── Spatial └── SQLite │ └── Ledger ├── Redis ├── MongoDB ├── Cassandra └── Neo4j

1. Relational Databases (RDBMS)

The most important category. Data is organized in tables (rows and columns) with strict schemas and relationships between tables.

-- Table: users
┌────┬─────────┬─────────────────────┬─────┐
│ id │  name   │       email         │ age │
├────┼─────────┼─────────────────────┼─────┤
│  1 │ Alice   │ alice@example.com   │  30 │
│  2 │ Bob     │ bob@example.com     │  25 │
│  3 │ Charlie │ charlie@example.com │  35 │
└────┴─────────┴─────────────────────┴─────┘

-- Table: orders (related to users via user_id)
┌────┬─────────┬────────────┬────────┐
│ id │ user_id │    date    │ amount │
├────┼─────────┼────────────┼────────┤
│  1 │    1    │ 2024-01-15 │  99.99 │
│  2 │    1    │ 2024-02-20 │  49.50 │
│  3 │    2    │ 2024-01-30 │ 199.00 │
└────┴─────────┴────────────┴────────┘

Key properties:

Major players:

DatabaseStrengthsCommon Use
PostgreSQLFeature-rich, extensible, standards-compliantGeneral purpose, best default choice
MySQL/MariaDBSimple, fast reads, huge ecosystemWeb apps, WordPress, simple workloads
SQLiteEmbedded, zero-config, single fileMobile, desktop, testing, edge
OracleEnterprise features, RAC clusteringBanks, large enterprises
SQL ServerWindows integration, BI toolsMicrosoft shops
💡 Default Choice

If you're unsure which database to use: start with PostgreSQL. It handles 90% of use cases well. Only reach for specialized databases when you have a specific need that PostgreSQL can't meet efficiently.

2. Key-Value Stores

The simplest model: store and retrieve values by a unique key. Like a giant hash map.

// Conceptually:
SET "user:123"'{"name":"Alice","email":"alice@ex.com"}'
GET "user:123"'{"name":"Alice","email":"alice@ex.com"}'
DEL "user:123"

Examples: Redis, Memcached, etcd, DynamoDB

Best for: Caching, session storage, real-time leaderboards, configuration

Limitation: Can only query by key. No "find all users where age > 30."

💡 Telecom Use

In 5G, session state (PDU sessions, UE contexts) is often stored in Redis or similar key-value stores for ultra-fast access. The key is the SUPI or session ID, the value is the serialized context.

3. Document Stores

Store semi-structured documents (usually JSON/BSON). Each document can have a different structure.

// MongoDB document — no fixed schema!
{
  "_id": "user_123",
  "name": "Alice",
  "email": "alice@example.com",
  "addresses": [
    {"type": "home", "city": "Stockholm"},
    {"type": "work", "city": "Gothenburg"}
  ],
  "preferences": {"theme": "dark", "lang": "en"}
}

Examples: MongoDB, CouchDB, Firestore

Best for: Content management, catalogs, user profiles with varying fields

Limitation: Weak/no joins, eventual consistency (often), no ACID across documents

4. Column-Family Stores

Optimized for writing and reading large amounts of data across many machines. Data is stored by column, not by row.

// Cassandra: optimized for write-heavy, distributed workloads
// Row key → columns (sparse, can vary per row)
Row "user:123":
  name: "Alice"
  email: "alice@ex.com"
  last_login: "2024-03-15"

Row "user:456":
  name: "Bob"
  phone: "+46701234567"    ← different columns per row!

Examples: Apache Cassandra, HBase, ScyllaDB

Best for: Time-series at scale, IoT data, write-heavy workloads, multi-datacenter

5. Graph Databases

Optimized for data with complex relationships (social networks, fraud detection, knowledge graphs).

(Alice)──FRIENDS_WITH──►(Bob) │ │ WORKS_AT WORKS_AT │ │ ▼ ▼ (Ericsson) (Volvo) │ LOCATED_IN │ ▼ (Stockholm)

Examples: Neo4j, Amazon Neptune, JanusGraph

Best for: Social networks, recommendation engines, fraud detection, network topology

6. Time-Series Databases

Optimized for timestamped data points (metrics, telemetry, IoT sensors).

// Typical time-series data:
timestamp            | metric      | value | host
2024-03-15 10:00:01 | cpu_usage   | 72.5  | server-1
2024-03-15 10:00:01 | memory_used | 8.2GB | server-1
2024-03-15 10:00:02 | cpu_usage   | 73.1  | server-1

Examples: InfluxDB, TimescaleDB, Prometheus, ClickHouse

Best for: Monitoring, IoT, financial data, network telemetry

7. Search Engines

Optimized for full-text search and analytics on unstructured text.

Examples: Elasticsearch, OpenSearch, Solr

Best for: Log analysis, full-text search, analytics dashboards

Decision Guide

Your NeedBest FitExample
General purpose, ACID, complex queriesRelationalPostgreSQL
Ultra-fast cache, simple lookupsKey-ValueRedis
Flexible schema, document-orientedDocumentMongoDB
Massive write throughput, distributedColumn-FamilyCassandra
Complex relationships, graph traversalGraphNeo4j
Metrics, monitoring, time-stamped dataTime-SeriesInfluxDB
Full-text search, log analysisSearchElasticsearch
⚠️ Common Mistake

Don't pick a database because it's trendy. Pick it because your access patterns match its strengths. MongoDB was overhyped in 2015 — many teams used it for data that was clearly relational, then suffered when they needed joins and transactions. Start relational, specialize only when needed.

Key Takeaways