Neo4j interview questions on Cypher, modeling and performance
Neo4j interview questions test whether you can think in graphs: modeling a domain as nodes, relationships and properties, writing Cypher that reads and writes those patterns, and keeping traversals fast with indexes, constraints and sensible relationship design. Senior rounds add MERGE concurrency, dense nodes, bulk loading, clustering and graph algorithms. The strongest answers explain when a graph database is the right tool and when a relational table would serve better.
By Evin JohnPublished 8 min read
How Neo4j shows up in interviews
Few interviews are only about Neo4j. It appears inside backend, data engineering and analytics loops at companies that run recommendation engines, fraud detection, identity and access graphs, supply chain networks, IT dependency maps or knowledge graphs for search and generative AI. Expect three kinds of questions. First, concept checks on the property graph model and how it differs from tables. Second, a live Cypher exercise on a small schema, often people, products and purchases or accounts and transfers. Third, a modeling discussion: here is a business problem, draw the nodes and relationships, then write the query that answers it. Graph data science roles add algorithms such as PageRank and community detection.
Fundamentals
| Question | What it tests | What a strong answer shows |
|---|---|---|
| What is a labeled property graph? | The model | Nodes carry zero or more labels (Person, Customer) and key-value properties. Relationships have exactly one type, a direction, a start and end node, and their own properties, such as a since date on WORKS_AT. |
| What does index-free adjacency mean? | Storage | Each node record points directly to its relationships, so hopping from one node to its neighbors is pointer chasing rather than an index lookup or a join. Traversal cost grows with the part of the graph you touch, not with the total size. |
| When is a graph database a better fit than a relational one? | Judgment | When questions follow connections of unknown or variable depth: friends of friends, shortest routes, ownership chains, fraud rings, impact of a failing server. Tables still win for wide aggregations over every row and plain transactional records. |
| Are relationships directed? Can you query them both ways? | Cypher basics | Every stored relationship has a direction, but a query can ignore it with (a)-[:KNOWS]-(b). For naturally symmetric facts you store one relationship and match without direction, instead of storing two. |
| Labels versus properties: how do you choose? | Modeling | Labels group nodes for fast filtering and index scope (a node can be both Person and Employee). Use a property for values with many distinct options, such as a status or a city, and labels for a small set of roles or types. |
| What do MATCH, OPTIONAL MATCH, CREATE and MERGE do? | Clauses | MATCH finds patterns and drops rows that do not match. OPTIONAL MATCH keeps the row and returns null, like a left join. CREATE always writes. MERGE matches the whole pattern or creates the whole pattern. |
| What is WITH used for? | Query pipelines | It ends one part of a query and passes chosen variables to the next, so you can filter on an aggregate, limit early, or change what is in scope, much like a subquery or a HAVING clause. |
| How do you pass values into a query safely? | Parameters | Use parameters such as $email rather than building query strings. They prevent Cypher injection and let the database reuse cached query plans. |
| Which editions and hosting options exist? | Platform awareness | A Community edition, an Enterprise edition with clustering, extra constraints and security features, and a managed cloud service (AuraDB). Exact feature splits change between releases, so check the current docs for the version you run. |
MATCH (me:Person {email: $email})-[:FRIEND]-(f:Person)-[:FRIEND]-(fof:Person)
WHERE fof <> me
AND NOT EXISTS { (me)-[:FRIEND]-(fof) }
RETURN fof.name AS suggestion, count(DISTINCT f) AS mutualFriends
ORDER BY mutualFriends DESC
LIMIT 10Intermediate: Cypher and modeling
- Why can MERGE create duplicates? MERGE checks the entire pattern. If a customer exists but the order relationship does not, MERGE (c:Customer {id: 1})-[:PLACED]->(o:Order {id: 9}) creates a brand-new customer as well. Merge each node on its key first, then merge the relationship between the bound variables.
- What are ON CREATE SET and ON MATCH SET? Clauses on MERGE that set properties only when the node was created, such as a createdAt time, or only when it already existed, such as a lastSeen time.
- How do variable-length paths work? A pattern such as -[:REPORTS_TO*1..4]-> follows between one and four hops. Always set an upper bound on large graphs, because an open-ended path can explode into millions of rows.
- How do you find the shortest route between two nodes? shortestPath() or allShortestPaths() over a bounded variable-length pattern. Recent Cypher 5 releases also add a SHORTEST keyword and quantified path patterns, so mention both and say which version you have used.
- What does UNWIND do? It turns a list into rows, which is how you write many records from one parameter list in a single query instead of one round trip per record.
- Should a fact be a property, a relationship or its own node? A simple attribute is a property. A link between two entities is a relationship. If the link itself needs relationships, such as an employment that has a manager and a contract, promote it to a node (Employment) between Person and Company.
- How do you model time-dependent data? Put validity dates on relationships for small histories, or use event nodes linked in order for timelines you need to traverse. Avoid a single node with a huge list of timestamps.
- What is the difference between collect() and count()? Both aggregate per group defined by the non-aggregated return columns. collect() builds a list, count() counts rows or non-null values, and count(DISTINCT x) removes duplicates that multiple paths produce.
CREATE CONSTRAINT customer_id IF NOT EXISTS
FOR (c:Customer) REQUIRE c.id IS UNIQUE;
CREATE CONSTRAINT order_id IF NOT EXISTS
FOR (o:Order) REQUIRE o.id IS UNIQUE;
// Risky: MERGE (c:Customer {id: $customerId})-[:PLACED]->(o:Order {id: $orderId})
MERGE (c:Customer {id: $customerId})
ON CREATE SET c.createdAt = datetime()
MERGE (o:Order {id: $orderId})
ON CREATE SET o.total = $total, o.placedAt = datetime()
MERGE (c)-[:PLACED]->(o);Performance, indexes and operations
| Question | What it tests | What a strong answer shows |
|---|---|---|
| What is the role of an index in a graph database? | Query planning | Indexes find the anchor nodes where a traversal starts, such as the person with this email. After that, relationships are followed directly. Without an index, the planner scans every node with the label. |
| Which index types does Neo4j offer? | Version awareness | In Neo4j 5, range indexes for equality and ranges, text indexes for string matching, point indexes for spatial values, full-text indexes for search, and vector indexes for similarity search in recent releases. Older versions used B-tree indexes. |
| EXPLAIN versus PROFILE? | Tuning | EXPLAIN shows the planned operators without running the query. PROFILE runs it and reports rows and db hits per operator, so you can spot an AllNodesScan or NodeByLabelScan where you expected an index seek. |
| What causes a Cartesian product warning? | Query bugs | Two disconnected patterns in one MATCH, so every row from one side pairs with every row from the other. Connect the patterns, or bind each side through an index and accept the product only when it is tiny. |
| What is a dense node or supernode and why does it hurt? | Modeling at scale | A node with a huge number of relationships, such as a celebrity account or a country node. Traversals through it fan out enormously. Use specific relationship types and directions, filter before expanding, or split the node, for example by year. |
| How do you load millions of rows? | Bulk loading | For a new database, the offline admin import tool is fastest. For a live one, LOAD CSV or a driver with UNWIND, batched into transactions of a few thousand to tens of thousands of rows, with constraints created first so MERGE uses an index. |
| How do drivers talk to Neo4j? | Application code | Over the Bolt protocol with official drivers for languages such as Java, Python, JavaScript, .NET and Go. Use one driver per application, short sessions, managed transaction functions that retry on transient errors, and parameters. |
LOAD CSV WITH HEADERS FROM 'file:///transfers.csv' AS row
CALL {
WITH row
MERGE (a:Account {id: row.fromId})
MERGE (b:Account {id: row.toId})
CREATE (a)-[:TRANSFER {amount: toFloat(row.amount), at: datetime(row.at)}]->(b)
} IN TRANSACTIONS OF 10000 ROWS;Senior and scenario questions
- Design a fraud ring check for a bank. Model Account, Person, Device, Phone and Address nodes, with USES and HAS relationships. Accounts that share devices or phone numbers form clusters. Find connected groups with a bounded traversal or a community detection algorithm, then score clusters by size and recent activity.
- Two services MERGE the same customer at the same moment and you get duplicates. Why, and how do you fix it? Without a uniqueness constraint, both transactions can miss the node and create it. A constraint gives MERGE a lock on the key and rejects the duplicate, so add it, and retry transient failures in the driver.
- A query was fast in testing and times out in production. What do you check? PROFILE it on production-sized data, look for scans instead of seeks, unbounded variable-length paths, a dense node in the middle of the pattern, and rows multiplying before an aggregation. Add WITH and LIMIT early, or collect intermediate results.
- How would you migrate part of a relational schema to Neo4j? Rows become nodes, foreign keys and join tables become relationships, and join-table columns become relationship properties. Keep the system of record clear, and decide whether Neo4j is fed by change data capture or batch jobs.
- How do clustering and read scaling work? In Enterprise, a set of primary servers agree on writes with a consensus protocol and secondaries serve reads. Bookmarks let a client read its own writes from another member. Name the version you used, since the terminology changed between 4.x and 5.
- When would you use the Graph Data Science library? For algorithms over the whole graph or large parts of it: PageRank for influence, Louvain or label propagation for communities, node similarity for recommendations, and path algorithms for routing. It works on an in-memory projection of the graph, not on the stored graph directly.
- How does a graph help retrieval for a language model? A knowledge graph gives entities and relationships that a retrieval step can follow, and vector indexes find similar text chunks. Combining both lets an answer cite connected facts, not just similar paragraphs.
- When would you argue against using Neo4j? When the workload is mostly reporting over every record, append-only events, or simple key lookups. Adding a second database brings sync, backup and skill costs, so the connected queries must be worth it.
Fictional example
- Interviewer
- We want to suggest colleagues who could help on a project. People report to managers, work on projects and have skills. How would you model it, and what is the query?
- Candidate
- I would have Person, Project and Skill nodes. A person REPORTS_TO another person, WORKS_ON a project with a role and start date on the relationship, and HAS_SKILL a skill with a level property. For the suggestion, I start from the project, find the skills its current members use, then look for people who have those skills but are not on the project, and rank them by how many of the needed skills they cover. I would put a uniqueness constraint on project and person IDs so the anchor lookups are index seeks. If one skill, say SQL, is shared by thousands of people, it becomes a dense node, so I would filter by skill level before expanding. Before shipping, I would PROFILE it on realistic data and check that the rows stay small until the final count.
How to prepare for Neo4j interview questions
- Run a local or cloud sandboxUse Neo4j Desktop, a container on your own machine or a free cloud instance, and load one of the built-in example datasets such as the movies graph.
- Write the core queries by handNeighbors, friends of friends, shortest path, top-N by degree, and a pattern with OPTIONAL MATCH. Then rewrite each with WITH to filter on an aggregate.
- Break MERGE on purposeCreate duplicates with a whole-pattern MERGE, then fix them with constraints and per-node MERGE. Being able to describe this from experience lands well.
- Read query plansPROFILE a query before and after adding an index and note how db hits change. Practice explaining the operators aloud.
- Prepare one modeling storyA domain you modeled as a graph, what you changed after the first version, and one thing you decided to keep in a relational store.
Graph questions overlap with general database rounds. Data modeling interview questions covers entities and keys from the relational side, MongoDB interview questions shows the document trade-offs, and GraphQL interview questions explains a query language that is often confused with graph databases despite the shared name.
Cypher is easier to explain after you have talked through a few patterns out loud. Natively, an AI interview assistant for Mac and Windows, transcribes a mock graph modeling round on your computer, can suggest answer points as the question is asked, and in practice reads a schema diagram, a query plan or a Cypher exercise from a screenshot. Pro or the free trial also takes your résumé and the job description into account, and the transcript and notes stay available so you can check where an explanation went vague.
Questions people ask
What are common Neo4j interview questions?
The labeled property graph and index-free adjacency, graph versus relational databases, MATCH, OPTIONAL MATCH, MERGE and WITH in Cypher, indexes and constraints, PROFILE output, dense nodes, bulk loading and a modeling exercise.
What is the difference between CREATE and MERGE in Cypher?
CREATE always writes the pattern. MERGE first looks for the whole pattern and creates all of it only if no match exists, so merge each node on a constrained key before merging the relationship to avoid duplicates.
When should you use a graph database instead of SQL?
When the main questions follow relationships of variable depth, such as recommendations, fraud rings, dependency impact or shortest paths. For reporting across every row or simple transactions, a relational database is usually simpler.
How do I prepare for a Neo4j interview?
Load a sample graph, write neighbor, friends-of-friends, shortest path and aggregation queries by hand, reproduce and fix a MERGE duplicate, read PROFILE plans, and prepare one graph modeling story from your own work.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
