Course contentsShow
← System Design
Lesson 452 of 1,91913. NoSQL: Graph DatabasesFree lesson

Graph Model: Nodes and Edges

Understanding nodes as entities and edges as relationships, with both supporting properties for rich data modeling.

Graph Model: Nodes and Edges

You'll learn: How graph databases represent data using nodes (entities) and edges (relationships), both enriched with properties for powerful data modeling.


The Core Idea

A graph database organizes data as a network of connected points, rather than tables or documents. This network consists of two fundamental building blocks:

  • Nodes (also called vertices): Represent entities like people, products, or locations
  • Edges (also called relationships): Represent connections between nodes, like "friends with," "purchased," or "located in"

Think of it like a social network map: each person is a node, and friendships are edges connecting those nodes.


Nodes: The Entities

Nodes are the "things" in your system. Each node can have:

  • Labels: Categories like Person, Product, or City
  • Properties: Key-value pairs storing data (e.g., name: "Alice", age: 30, email: "alice@example.com")

A node is self-contained but gains meaning through its relationships.


Edges: The Relationships

Edges define how nodes connect. Each edge can have:

  • Type/Label: Describes the relationship (e.g., FOLLOWS, BOUGHT, LIVES_IN)
  • Direction: Points from one node to another (though some systems support undirected edges)
  • Properties: Additional context like since: "2020", weight: 5, or rating: 4.5

Properties on edges make relationships first-class citizens, not just pointers. You can query "Who became friends after 2020?" directly.


Rich Data Modeling

Unlike relational databases where relationships are implicit (foreign keys), graph databases make relationships explicit and queryable. Both nodes and edges carry properties, enabling complex queries like "Find friends of friends who bought the same product" without expensive joins.

Key Takeaway: Graph databases use nodes to represent entities and edges to represent relationships, with both supporting properties that enable expressive, relationship-centric data modeling.