Interview's MateData Engineer
Interview's Mate

Data Engineer

SQL · Spark · Lakehouse · Streaming

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Engineer topics
Lesson 38/ 160
02. Advanced SQL & Relational Databases

Graph Databases Basics (Neo4j & Cypher)

Model highly connected data with nodes/relationships and query paths using Cypher.

IntermediateNeo4j · Cypher · Graph3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Stable node labels and relationships. Next, indexed starting property rather than full graph scan. Finally, aggregate evidence and avoid oversized path JSON.

Think of it like…

A graph is a road map stored with the roads attached to intersections, making 'find three turns from this station' cheaper than assembling every road junction on demand.

Where you’ve seen it

MATCH (a:Account {id:$id})-[:SENT_TO*1..3]->(b:Account) RETURN DISTINCT b.id; an index on :Account(id) anchors the search and *1..3 caps path expansion.

Words you’ll hear

Neo4j
A property graph database optimized for labeled nodes, typed relationships, indexes, and transactional online graph workloads.
Cypher
Neo4j's declarative pattern-matching language, often read as visual node and relationship shapes.
Graph
A sequence of nodes connected by relationships whose variable length must be bounded for predictable work.
Operational boundary
Labeling a graph as magical avoids index and cardinality work; an unconstrained variable-length path can explore a combinatorial network and return huge duplicate result sets. Model only high-connectivity domains, index anchor properties, bound traversal depth and relationship types, profile expanded rows, and return projection-specific paths rather than whole subgraphs.

Visual diagram

Loading interactive diagram

Theory & deep dive

Neo4j: the working mechanism

A graph database stores entities as nodes and facts as relationship records, so path and neighborhood traversal follows stored edges instead of repeatedly joining relational association tables.

Stable node labels and relationships. Indexed starting property rather than full graph scan, then constrained types, direction, depth, and uniqueness; this exposes the state governed by Graph.

Graph Databases Basics in one concrete design

MATCH (a:Account {id:$id})-[:SENT_TO*1..3]->(b:Account) RETURN DISTINCT b.id; an index on :Account(id) anchors the search and *1..3 caps path expansion.

Key takeaway: A graph database stores entities as nodes and facts as relationship records, so path and neighborhood traversal follows stored edges instead of repeatedly joining relational association tables

Graph Databases Basics: failure mode and production response

Labeling a graph as magical avoids index and cardinality work; an unconstrained variable-length path can explore a combinatorial network and return huge duplicate result sets.

Model only high-connectivity domains, index anchor properties, bound traversal depth and relationship types, profile expanded rows, and return projection-specific paths rather than whole subgraphs. Track Anchor cardinality as "a selective start node before traversal", and make Hop bound visible to the dataset owner.

Key takeaway: Model only high-connectivity domains, index anchor properties, bound traversal depth and relationship types, profile expanded rows, and return projection-specific paths rather than whole subgraphs.

How it works, step by step

Step 1 of 4
Neo4j

1. Model entities

Stable node labels and relationships. A graph database stores entities as nodes and facts as relationship records, so path and neighborhood traversal follows stored edges instead of repeatedly joining relational association tables.

stable node labels and relationships
Key numbers at this step
Anchor cardinality
a selective start node before traversal
Cypher
Neo4j's declarative pattern-matching language, often read as visual node and relationship shapes.

When to use it & trade-offs

What it is

A graph database stores entities as nodes and facts as relationship records, so path and neighborhood traversal follows stored edges instead of repeatedly joining relational association tables. MATCH (a:Account {id:$id})-[:SENT_TO*1..3]->(b:Account) RETURN DISTINCT b.id; an index on :Account(id) anchors the search and *1..3 caps path expansion.

Why it matters: Labeling a graph as magical avoids index and cardinality work; an unconstrained variable-length path can explore a combinatorial network and return huge duplicate result sets. Model only high-connectivity domains, index anchor properties, bound traversal depth and relationship types, profile expanded rows, and return projection-specific paths rather than whole subgraphs.

When to reach for it

  • Model highly connected data with nodes/relationships and query paths using Cypher.
  • Choose Neo4j because it provides this capability: A property graph database optimized for labeled nodes, typed relationships, indexes, and transactional online graph workloads.
  • Keep evidence for Anchor cardinality at "a selective start node before traversal" so the last production stage-Project - aggregate evidence and avoid oversized path JSON-remains testable.

When to avoid or be careful

  • Labeling a graph as magical avoids index and cardinality work; an unconstrained variable-length path can explore a combinatorial network and return huge duplicate result sets.
  • Do not conflate Cypher with Neo4j. The second concept contributes different behavior: Neo4j's declarative pattern-matching language, often read as visual node and relationship shapes.
  • Release only after this guardrail is in place: Model only high-connectivity domains, index anchor properties, bound traversal depth and relationship types, profile expanded rows, and return projection-specific paths rather than whole subgraphs.

Neo4j / Cypher / Graph - roles, limits, and operating cost

Neo4j
Best for: A property graph database optimized for labeled nodes, typed relationships, indexes, and transactional online graph workloads.

Strengths: A property graph database optimized for labeled nodes, typed relationships, indexes, and transactional online graph workloads. A graph database stores entities as nodes and facts as relationship records, so path and neighborhood traversal follows stored edges instead of repeatedly joining relational association tables.

Watch out: Labeling a graph as magical avoids index and cardinality work; an unconstrained variable-length path can explore a combinatorial network and return huge duplicate result sets.

Cypher
Best for: Neo4j's declarative pattern-matching language, often read as visual node and relationship shapes.

Strengths: Neo4j's declarative pattern-matching language, often read as visual node and relationship shapes. In this workflow it supports: Traverse - constrained types, direction, depth, and uniqueness.

Watch out: The operating cost is real: explicit maximum for variable-length paths.

Graph
Best for: A sequence of nodes connected by relationships whose variable length must be bounded for predictable work.

Strengths: A sequence of nodes connected by relationships whose variable length must be bounded for predictable work. Its output can be checked with Expanded rows.

Watch out: Operating guardrail: Model only high-connectivity domains, index anchor properties, bound traversal depth and relationship types, profile expanded rows, and return projection-specific paths rather than whole subgraphs.

Interview signals & numbers to know

When this topic comes up

  • “Where is the failure boundary for Neo4j, and how would Anchor cardinality reveal it?”
  • “Why is Cypher distinct from this behavior: a sequence of nodes connected by relationships whose variable length must be bounded for predictable work?”
  • Production clue: Labeling a graph as magical avoids index and cardinality work; an unconstrained variable-length path can explore a combinatorial network and return huge duplicate result sets.
  • Design probe: Model only high-connectivity domains, index anchor properties, bound traversal depth and relationship types, profile expanded rows, and return projection-specific paths rather than whole subgraphs.

Benchmarks & rules of thumb

Anchor cardinality -
a selective start node before traversal
Hop bound -
explicit maximum for variable-length paths
Expanded rows -
track query plan operator growth, not only final results

Common mistakes & follow-ups

Common interview mistakes

  • Labeling a graph as magical avoids index and cardinality work; an unconstrained variable-length path can explore a combinatorial network and return huge duplicate result sets.
  • Reporting success from a job exit code without checking Anchor cardinality and Hop bound.
  • Treating this example as complete without replay, rollback, or access boundaries: MATCH (a:Account {id:$id})-[:SENT_TO*1..3]->(b:Account) RETURN DISTINCT b.id; an index on :Account(id) anchors the search and *1..3 caps path expansion.

Likely interviewer follow-ups

  • How would you prove this contract instead of only checking that the command ran: A property graph database optimized for labeled nodes, typed relationships, indexes, and transactional online graph workloads.
  • What does the recovery plan do when this occurs? Labeling a graph as magical avoids index and cardinality work; an unconstrained variable-length path can explore a combinatorial network and return huge duplicate result sets.
  • When is Neo4j insufficient for Hop bound, and what does adding Cypher cost in Anchor cardinality?
Interview tip: Lead with the data path and failure boundary: A graph database stores entities as nodes and facts as relationship records, so path and neighborhood traversal follows stored edges instead of repeatedly joining relational association tables. Then make the answer operational: Model only high-connectivity domains, index anchor properties, bound traversal depth and relationship types, profile expanded rows, and return projection-specific paths rather than whole subgraphs.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Graph Databases Basics (Neo4j & Cypher) with data engineer interview Q&A and hands-on practice.

Open Data Engineer Q&A →Machine Learning Q&A
Previous topic
NoSQL Databases Overview (Document: MongoDB, Key-Value: Redis, Wide-Column: Cassandra)
Next topic
Change Data Capture (CDC) Fundamentals (Logical Replication & Binlogs)