Graph Database
- In Turkish
- Çizge Veritabanı
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
// 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
- GraphData Structures, p. 15A graph is a data structure made of nodes, called vertices, connected by edges, and is used to model relationships such as roads, friendships, and dependencies.
- NoSQLDatabases, p. 29NoSQL is a family of databases that store data in models other than relational tables, such as documents, key-value pairs, wide columns, or graphs.
- Relational DatabaseDatabases, p. 38A relational database stores data in tables of rows and columns, links those tables through keys, and lets you query and combine the data with SQL.
- SQL JOINDatabases, p. 41A SQL JOIN is a query operation that combines rows from two or more tables into one result, matching them on related columns such as a foreign key.
- Breadth-First SearchData Structures, p. 8Breadth-first search is a graph traversal algorithm that visits nodes in order of their distance from the start, exploring all neighbors before going deeper.
- GraphQLBackend & APIs, p. 19GraphQL is a query language and runtime for APIs that lets clients request exactly the data they need, often from a single endpoint in a single request.
Spotted a mistake or something missing on this page?Suggest an edit