<< back to Guides

๐Ÿงฉ Guide to Database Models: From Flat Files to Star Schemas

A Database Model defines how data is structured, stored, and related within a database system. Choosing the right model depends on the systemโ€™s complexity, access patterns, performance, and consistency needs.

This guide covers the most widely used database models with examples and trade-offs.


๐Ÿ“„ 1. Flat File Model

๐Ÿง  Concept

The simplest model โ€” all data is stored in a single table or file, often in CSV or TSV format.

โœ… Use Cases

// Example CSV
UserId,Name,Age
1,Alice,30
2,Bob,25

โš ๏ธ Limitations


๐ŸŒฒ 2. Hierarchical Model

๐Ÿง  Concept

Data is organized in a tree-like structure, with parent-child relationships (like XML).

// Pseudocode structure
Company
 โ”œโ”€โ”€ Department
 โ”‚    โ”œโ”€โ”€ Employee
 โ”‚    โ””โ”€โ”€ Employee
 โ””โ”€โ”€ Department
      โ””โ”€โ”€ Employee

โœ… Use Cases

โš ๏ธ Limitations


๐Ÿ”— 3. Network Model

๐Ÿง  Concept

Like the hierarchical model, but supports many-to-many relationships via graph-like links.

// Simplified example
Employee {
  ID: 1
  WorksOn: [Project1, Project2]
}

โœ… Use Cases

โš ๏ธ Limitations


๐Ÿงฑ 4. Relational Model

๐Ÿง  Concept

Data is stored in tables (relations). Relationships are managed via foreign keys.

// SQL table example
CREATE TABLE Orders (
  OrderID INT PRIMARY KEY,
  UserID INT,
  Amount DECIMAL,
  FOREIGN KEY (UserID) REFERENCES Users(UserID)
);

โœ… Use Cases

โš–๏ธ Trade-offs

Pros Cons
Strong data integrity Harder to scale horizontally
SQL is powerful Complex joins impact performance

โญ 5. Star Schema (Dimensional Model)

๐Ÿง  Concept

Used in data warehousing, a central fact table connects to denormalized dimension tables.

// Star schema layout
FactSales
 โ”œโ”€โ”€ DateID
 โ”œโ”€โ”€ ProductID
 โ”œโ”€โ”€ StoreID

DimensionDate
DimensionProduct
DimensionStore

โœ… Use Cases

โš–๏ธ Trade-offs

Pros Cons
Fast read performance Redundant data (denormalized)
Simpler to query Less normalized = update cost

โ„๏ธ 6. Snowflake Schema

๐Ÿง  Concept

Like a star schema, but dimension tables are normalized (split into sub-tables).

// Snowflake schema layout
FactSales
 โ”œโ”€โ”€ ProductID

DimensionProduct
 โ””โ”€โ”€ ProductCategory
      โ””โ”€โ”€ ProductDepartment

โœ… Use Cases

โš–๏ธ Trade-offs

Pros Cons
More normalized More complex queries
Space efficient Requires joins

๐Ÿงฎ 7. Object-Oriented Model

๐Ÿง  Concept

Combines database concepts with object-oriented programming. Objects contain data and methods.

// Example object
class User {
  int id;
  String name;
  Address address;
}

โœ… Use Cases


๐Ÿง  8. Document Model (NoSQL)

๐Ÿง  Concept

Stores data as JSON-like documents, which can be deeply nested.

// MongoDB document
{
  "userId": "123",
  "name": "Alice",
  "orders": [
    { "orderId": "a1", "amount": 50 },
    { "orderId": "a2", "amount": 100 }
  ]
}

โœ… Use Cases


๐Ÿ•ธ๏ธ 9. Graph Model

๐Ÿง  Concept

Data is stored as nodes and edges, ideal for traversing relationships.

// Graph elements
(User)-[FRIENDS_WITH]->(AnotherUser)

โœ… Use Cases

Examples: Neo4j, Amazon Neptune


๐Ÿ“ฆ Comparison Summary

Model Use Case Strengths Weaknesses
Flat Logs, configs Simplicity No relationships
Hierarchical XML data, filesystems Tree-like queries Rigid
Network Legacy complex systems Many-to-many Complex navigation
Relational Transactions, business apps ACID, mature SQL support Scaling joins is difficult
Star Data warehousing Fast reads, easy queries Denormalized
Snowflake Data warehouses (normalized) Storage-efficient Complex joins
Object-Oriented OOP apps Aligns with code models Less adoption
Document CMS, NoSQL apps Flexible, nested structures Limited query capabilities
Graph Networked data Relationship traversal is fast Less suited for tabular data

๐Ÿ“˜ Resources


<< back to Guides