Thursday, February 13, 2020

Types of Database Models

  • Relational
  • Document
  • Graph


Summary

  Document database models target use cases where data comes in self-contained documents and relationships between documents are rare. Graph databases target when there are a large amount of many-to-many. Relational are when there is both many-to-one and many-to-many. 


Relational (Best known: SQL)

  The relational model organizes data into relations (tables), with each relation being an unordered collection of tuples (rows). 

  Relational database models tend to enforce schema on write. Essentially requiring every table/row to have the same schema. The application code will then know exactly the schema to expect. 


Factors

  • Strong many-to-one and many-to-many relationships
    • Joins can be done in the query
    • Good for removing duplication
  • Migrations
  • Non-locality when normalized
  • Declarative programming queries

Document

  The document model organizes data into documents (trees).

  Document database models enforce schema on read (i.e. we can write any document structure), but when we read the document back, our application code needs to handle the logic of the document structure.


Factors

  • Strong one-to-many relationships
  • Handles heterogeneous data
  • Imperative programming queries


Graph

  The graph model organizes data into entities (vertices/nodes) and relationships (edges).

  They also only enforce schema on read.


Future Factors:

  • Fault-tolerance
  • handling of concurrency