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, orCity - 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, orrating: 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.