Skip to content
Tutorials Center
My learning

Topics

Lesson 8 of 79 ยท Data Models and ER Modelling

Data Models Compared

Compare hierarchical, network, relational, object, document, graph and key-value data models, learn why relational won, and see one example in several shapes.

A data model is a set of ideas for describing data: what the basic building blocks are, how they connect, what operations you may perform and which rules you can state. Every DBMS is built around one. The model decides what a query looks like, which mistakes the system can catch, and which workloads feel natural.

Over sixty years, designers have tried many models. Some are historical, some dominate today, and some are enjoying a second life in modern NoSQL systems. This lesson is a tour. You do not need to memorize details; the goal is to see why the relational model became the default for business data, and when another model is the better tool.

Only the relational model can run live in this lesson. The other models are shown as read-only sketches, because the engines behind them (MongoDB, Neo4j, Redis and so on) are separate servers. Where SQLite can imitate an idea, you can try it.

Models at a glance

Early models

Hierarchical Records form a tree; each has one parent.
Network Records link in a graph with explicit pointers.

Fast for known paths, painful when questions change.

1 / 3

Hierarchical model

Data forms a tree: each record (segment) has exactly one parent. An order belongs to one customer, and its lines belong to the order. Access follows paths from the root. This is fast for the one path the designers expected and awkward for everything else; a many-to-many relationship, such as students and courses, needs duplicate records. IBM's IMS (1960s) is the classic example, and the same tree idea survives in file systems and XML.

Network model

The network model (CODASYL, 1970s) lets a record have several parents by linking records into a graph through named "sets". Programs navigate record by record with pointers: find the first order of this customer, then the next, then the owner. It handles many-to-many data, but programmers must know the physical links, so changing the structure breaks programs. This is the problem data independence (previous chapter) was invented to solve.

Relational model

In 1970 Edgar Codd proposed storing data as relations (tables) and querying with a high-level, mathematical language instead of pointer navigation. Relationships are expressed by values: an order row holds the customer's id. The system, not the programmer, decides how to find rows. This brought data independence, a firm theory (relational algebra and normalization) and SQL. The rest of this tutorial focuses on it.

Object-oriented and object-relational models

Applications written in object-oriented languages work with objects that have fields, references and methods. Object databases store them directly, avoiding the "impedance mismatch" of converting between objects and rows. Pure object databases stayed niche. Instead, relational systems absorbed the ideas and became object-relational: user-defined types, arrays, JSON columns and inheritance in products like PostgreSQL.

Document model

A document database stores self-contained, nested records, usually JSON. A whole order, with its customer snapshot and lines, is one document. There is no fixed schema enforced for all documents, so structure can evolve per record. Reading one aggregate is a single lookup. The costs: duplication across documents, and joins across documents are limited or manual.

Key-value model

The simplest model: a key maps to a value the database treats as opaque (or lightly structured). get(key) and put(key, value) are extremely fast and easy to scale across machines. Caches, session stores and counters use it. You cannot ask "all values where the price is above 10" without scanning or maintaining your own index.

Column-family (wide-column) model

Systems in the Bigtable family store rows under a key, with columns grouped into families and a flexible set of columns per row, distributed across many servers for huge write volumes. Do not confuse this with column stores used for analytics (OLTP vs OLAP).

Graph model

A graph database stores nodes (things) and edges (relationships), both with properties. Traversals such as "friends of friends who like jazz" are cheap, because following a relationship is a direct hop and not a join. Social networks, fraud detection and recommendation engines favor it.

One piece of data, several models

Take a single order: customer Ada bought two books. Here it is in the shapes above. The first two are read-only sketches.

JSON
// Document model: one aggregate
{
  "order": 1001,
  "customer": { "id": 7, "name": "Ada" },
  "lines": [
    { "title": "Dune",  "qty": 1 },
    { "title": "Emma",  "qty": 2 }
  ]
}
TEXT
# Key-value model: opaque values behind keys
order:1001           -> {"customer":7,"lines":[["Dune",1],["Emma",2]]}
customer:7:name      -> Ada

# Graph model (Cypher-style notation, shown only): nodes and edges
(:Customer {name:"Ada"})-[:PLACED]->(:Order {id:1001})-[:CONTAINS {qty:2}]->(:Book {title:"Emma"})

The relational version splits the same facts into tables and links them by keys.

SQL The relational shape

Press Run (or Ctrl + Enter) to see the result here.

The facts are the same, but they are now split and joined by values. A different question, such as "total copies of each title across all orders", needs no new structure, only a new query. In the document form that question means scanning every document.

SQLite can also hold a document inside a column using its JSON functions, which shows how relational systems borrow from the document model:

SQL A document inside a relational column

Press Run (or Ctrl + Enter) to see the result here.

The CHECK constraint keeps even the document column honest. NoSQL Databases returns to this trade-off in depth.

Why relational won

  1. Declarative queries. Ask for the result; the optimizer finds the path.
  2. Data independence. Storage and indexes can change without rewriting programs.
  3. A firm foundation. Relational algebra and normalization give provable guidance.
  4. Strong guarantees. Transactions, constraints and ACID keep business data correct.
  5. Ad hoc questions. Because data is not tied to one access path, new questions are cheap.

Relational databases are not best at everything. Choose the model by the access pattern: nested aggregates fit documents, hot lookups fit key-value stores, relationship-heavy traversals fit graphs. Many systems today are multi-model or combine several stores, which is called polyglot persistence.

A short timeline

Decade Milestone
1960s Hierarchical (IMS) and network (CODASYL) systems
1970 Codd publishes the relational model
1970s System R and Ingres prototypes; SQL is born
1980s Commercial relational systems spread; SQL standardized
1990s Object databases rise and fade; object-relational features appear
2000s Web scale: key-value, document and wide-column NoSQL systems
2010s Graph databases grow; NewSQL combines SQL with scale-out
2020s Relational systems add JSON, vectors and more; multi-model engines

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In the hierarchical model, how many parents does a record have?

    Hierarchical data is a tree, so every record except the root has one parent.
  2. 2. What was the key idea that set the relational model apart from the network model?

    Codd replaced pointer navigation with a declarative, mathematical approach, which gave data independence.
  3. 3. Which model is the best fit for 'find friends of friends who share an interest'?

    Graph databases make multi-hop relationship traversal a first-class, efficient operation.
  4. 4. A drawback of storing each order as one self-contained document is:

    Documents make single-aggregate reads fast but make shared facts duplicated and cross-document queries harder.

Summary

  • A data model defines the building blocks, relationships, operations and constraints of a database.
  • Hierarchical and network models used fixed paths and pointers; the relational model replaced them with tables, declarative queries and data independence.
  • Document, key-value, wide-column and graph systems each optimize a different access pattern.
  • SQLite can combine tables with JSON, showing how relational systems absorb other models.
  • Choose the model by workload; many real systems use more than one.

Next: the standard way to design a relational database starts with a picture, in The Entity-Relationship Model.