Skip to main content

Graph Database

Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/graph-database

In short

A graph database stores data as nodes connected by relationships, which makes it fast to follow links such as friends of friends or dependencies between items.

What is a graph database?

A graph database stores data as a graph: nodes represent things such as people, products, or servers, and edges represent the relationships between them, such as follows, bought, or depends on. Both nodes and relationships can carry properties, for example a since date on a friendship. Relationships are stored as real data rather than worked out at query time.

Many graph databases use a design called index-free adjacency, where each node keeps direct references to its neighbors. Following a relationship is then a quick hop instead of an index lookup, so the cost of a query depends on how much of the graph it touches, not on the total size of the database. Property graph databases such as Neo4j are queried with languages like Cypher or the ISO standard GQL published in 2024, while RDF triple stores, used for linked data, are queried with SPARQL.

A graph database works like a subway map: stations are nodes, lines are relationships, and finding a route means following lines from station to station rather than looking every station up in a table. That makes it a good fit for social networks, recommendation engines, fraud detection that looks for rings of accounts sharing cards or devices, knowledge graphs, and maps of network or service dependencies.

A graph database is often compared with a relational database. Relational databases can model relationships with foreign keys and join tables, but a query that follows many hops needs a chain of self-joins that becomes slow and hard to write, while a graph database is built for exactly that. For totals and reports across whole tables, a relational database is usually the better tool. A graph database is also different from an in-memory graph data structure and has nothing to do with GraphQL, which is an API query language.

Key takeaways

  • Data is stored as nodes and relationships, both of which can have properties.
  • Following a relationship is a direct hop, so deep traversals stay fast.
  • Common query languages include Cypher, GQL, and SPARQL.
  • Typical uses are social networks, recommendations, fraud detection, and knowledge graphs.
  • Graph databases are unrelated to GraphQL, despite the similar name.

Example

Finding friends of friends with Cyphercypher
// Create two people and a relationship between them
CREATE (:Person {name: "Ada"})-[:FOLLOWS]->(:Person {name: "Linus"});

// Suggest people that Ada's follows follow, but Ada doesn't yet
MATCH (me:Person {name: "Ada"})-[:FOLLOWS]->()-[:FOLLOWS]->(other:Person)
WHERE other <> me AND NOT (me)-[:FOLLOWS]->(other)
RETURN DISTINCT other.name;

Readers ask

Is GraphQL a graph database?

No. GraphQL is a query language for APIs that lets clients choose which fields they receive, and it can sit in front of any kind of database. A graph database is a storage system built around nodes and relationships.

When should I use a graph database?

Use one when your most important queries follow relationships several levels deep, such as shortest paths, recommendations, or detecting connected groups. If most queries filter and aggregate rows, a relational database is usually simpler.

What query language do graph databases use?

Property graph databases commonly use Cypher or GQL, the ISO standard graph query language, and some use Gremlin. RDF triple stores use SPARQL.

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings