Dgraph — Distributed Native GraphQL Database
Dgraph is a horizontally scalable graph database with native GraphQL as a query language. It stores relationships as first-class citizens and handles billions of edges — the go-to choice when graph traversals at scale matter.
Installation avec revue préalable
Cet actif nécessite une revue. Le prompt copié demande un dry-run, affiche les écritures, puis continue seulement après confirmation.
npx -y tokrepo@latest install 08c928a8-37d2-11f1-9bc6-00163e2b0d79 --target codexDry-run d'abord, confirmez les écritures, puis lancez cette commande.
What it is
Dgraph is a horizontally scalable graph database that treats relationships as first-class citizens and uses GraphQL as its native query language. Unlike relational databases that bolt on graph capabilities through joins, Dgraph stores edges natively and traverses them in constant time regardless of dataset size.
Dgraph targets teams building social networks, recommendation engines, knowledge graphs, fraud detection systems, and any application where relationship traversals dominate query patterns.
How it saves time or tokens
Dgraph eliminates the impedance mismatch between your data model and your query language. If your data is a graph, you query it as a graph. There is no need to flatten relationships into join tables or maintain denormalized copies for performance. The native GraphQL API means frontend teams can query the database directly without a middleware translation layer. Horizontal sharding across nodes lets you scale without query rewrites.
How to use
- Start Dgraph with Docker:
docker run -d --name dgraph \
-p 8080:8080 -p 9080:9080 \
dgraph/standalone:v23.1
- Define a schema via the GraphQL endpoint:
type Person {
name: String! @search(by: [term])
friends: [Person] @hasInverse(field: friends)
age: Int @search
}
- Mutate and query data:
mutation {
addPerson(input: [
{name: "Alice", age: 30, friends: [{name: "Bob", age: 25}]}
]) {
person { name friends { name } }
}
}
query {
queryPerson(filter: {name: {anyofterms: "Alice"}}) {
name
age
friends { name age }
}
}
Example
A DQL (Dgraph Query Language) query for traversing friend-of-friend relationships:
{
friends_of_friends(func: eq(name, "Alice")) {
name
friends {
name
friends {
name
age
}
}
}
}
Related on TokRepo
- Database tools — AI-assisted database utilities and connectors
- Knowledge graph tools — resources for building and querying knowledge graphs
Common pitfalls
- Running the standalone Docker image in production limits you to a single node. Deploy Alpha and Zero nodes separately for fault tolerance and horizontal scaling.
- Schema changes that modify index types require a background reindex. Plan index strategy before loading large datasets.
- DQL and GraphQL have different capabilities. DQL supports recursive queries and aggregations that GraphQL mode does not expose directly.
Questions fréquentes
GraphQL is the standard API for CRUD operations with schema enforcement. DQL (formerly GraphQL+-) is Dgraph's native query language with additional features like recursive traversals, aggregations, and variable blocks. DQL is more powerful but less portable.
Dgraph shards data across Alpha nodes using a predicate-based sharding strategy managed by Zero nodes. Adding more Alpha nodes increases capacity. Zero nodes handle cluster coordination and shard rebalancing automatically.
Dgraph excels at relationship-heavy queries but lacks features like SQL transactions with isolation levels and complex aggregation pipelines. It works best as a complement to relational databases, handling the graph portion of your data model.
Yes. Dgraph supports distributed ACID transactions across shards. Mutations are atomic and consistent, with snapshot isolation for concurrent reads.
Dgraph provides official clients for Go, Java, Python, and JavaScript. The GraphQL endpoint works with any HTTP client or GraphQL library. Community clients exist for Rust, C#, and other languages.
Sources citées (3)
- Dgraph GitHub— Dgraph is a horizontally scalable graph database with native GraphQL
- Dgraph Documentation— DQL supports recursive queries and aggregations
- Dgraph Design Concepts— Distributed ACID transactions across shards
En lien sur TokRepo
Fil de discussion
Actifs similaires
OceanBase — Distributed SQL Database for Enterprise Workloads
Scalable distributed relational database supporting both OLTP and OLAP with MySQL and Oracle compatibility, built for financial-grade reliability.
WatermelonDB — Reactive Database for React Native Apps
A high-performance reactive database framework for React Native and React web apps, built on top of SQLite with lazy loading and sync primitives.
Apache Pulsar — Cloud-Native Distributed Messaging and Streaming
Apache Pulsar is a cloud-native distributed messaging and streaming platform. It combines the best of traditional messaging (like RabbitMQ) with streaming (like Kafka) — providing multi-tenancy, geo-replication, and tiered storage in a single system.
JuiceFS — Cloud-Native POSIX File System Built on Object Storage
A high-performance distributed file system that stores data in object storage like S3 while keeping metadata in Redis, PostgreSQL, or MySQL for cloud-native workloads.