Reading — step 1 of 5
Read
~1 min readGraph Models
Property Graph Model
Property graph elements:
- Node (vertex): an entity. Has labels (categories) + properties (key-value).
- Edge (relationship): a connection. Has a type, direction, properties.
Node Person { id: 1, name: "Alice", age: 30 }
Node Company { id: 100, name: "Acme" }
Edge WORKS_AT { since: 2020, role: "engineer" } from 1 to 100
Cypher (Neo4j's query language):
CREATE (alice:Person {name: 'Alice', age: 30})
CREATE (acme:Company {name: 'Acme'})
CREATE (alice)-[:WORKS_AT {since: 2020, role: 'engineer'}]->(acme)
Labels are tags: a Person can also be Engineer, Citizen. Edges always have a type (KNOWS, WORKS_AT, BOUGHT) and direction.
Internal representation:
- Each node has an ID (generated or user-provided).
- Each edge has an ID, source node, target node, type.
- Properties stored in a separate property file (or inline if small).
Constraints:
- Uniqueness: enforce uniqueness on a property (e.g. email).
- Existence: ensure required properties are present.
- Index: speed up lookup by property.
vs Relational:
- Relational: tables (rows = entities), foreign keys (relationships).
- Property graph: relationship is its own thing with own properties.
- Many-to-many in relational needs a junction table; graph just has edges.
Schema-flexibility: a graph DB can mix wildly different node types in the same DB. Most allow optional schema (Neo4j has schema constraints; not strict).
Indexes:
- Per-label: index name property of Person nodes.
- Composite: (label, property1, property2).
- Full-text: tokenize properties for search.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…