Skip to content
IT glossary
DatabasesUpdated December 3, 2026

Graph database

Графовая база данных

This kind of database represents entities as nodes and their connections as edges. It is useful when queries need to follow several connections, such as finding everyone who reports to a manager directly or indirectly.

Also known as: Neo4j

What makes a database a graph database?

Imagine a course catalog where some courses require others. Listing the prerequisites for one course is easy. Finding everything a student needs to take before that course means following prerequisites of prerequisites. A graph database represents each course as a node and each prerequisite as an edge. The question becomes: which nodes can I reach by following these edges?

How the model and queries work

Neo4j is one graph database product, not another name for the category. It uses the property graph model: nodes can have labels such as Course, relationships have a type and direction, and both can carry key–value properties. For example, a course might have a code, while a prerequisite relationship might record when the rule took effect. Not every graph database uses this model: RDF stores represent facts as subject–predicate–object triples.

Many graph queries describe a pattern rather than spelling out each step of the traversal. The query engine might use an index to locate a starting node and then follow relationships that match the requested type and direction. An index can make the starting lookup cheap, but it does not make the traversal cheap: if each node has many matching edges, the number of candidate paths can grow rapidly with depth.

Example: find indirect prerequisites

This Neo4j query uses Cypher to find courses reachable from CS301 in one to three REQUIRES steps:

MATCH (c:Course {code: 'CS301'})-[:REQUIRES*1..3]->(p:Course)
WHERE p <> c
RETURN DISTINCT p.code AS prerequisite

The arrow points from a course to a prerequisite. The depth limit means the query can miss prerequisites four or more steps away. The WHERE clause keeps a cycle from putting the starting course in the output, and DISTINCT returns each prerequisite code only once, even if several paths lead to it. Deduplicating the output does not eliminate the work of finding those paths.

When is it a good fit?

Graph databases are worth considering when multi-step relationship queries are central to the application. Examples include finding downstream effects of a software dependency, or identifying groups of accounts connected through shared payment details. Having relationships is not enough to justify a graph database, though. A relational database can also represent edges using a table with two foreign keys and follow them with a recursive CTE. If the application mainly does key lookups and a few predictable joins, a relational database may be the simpler choice.

How it comes up in interviews

You might be asked how to find every course affected by a change to a prerequisite. Explain that you would follow incoming REQUIRES edges rather than outgoing ones. Then clarify whether the interviewer wants unique courses, every dependency path, or just the shortest chain: these are different queries and can have very different costs.