Introduction
Dgraph is a graph database that speaks GraphQL as a first-class query language. Unlike Neo4j's Cypher or Gremlin, Dgraph lets you point a GraphQL schema at the database and get a ready-to-use API — with traversals, aggregations, and filters all expressed in GraphQL itself.
With over 21,000 GitHub stars, Dgraph is designed for horizontal scale. It shards data across machines using a purpose-built Raft-based cluster (no external coordinator), making it one of the few truly distributed graph databases.
What Dgraph Does
Dgraph stores triples (subject, predicate, object) — the classic graph primitive — but exposes them as typed GraphQL objects with relationships. Schema directives like @search, @dgraph, @hasInverse, and @auth control indexing, naming, inverse edges, and row-level authorization.
Architecture Overview
Client (GraphQL / DQL / gRPC)
|
[Zero nodes] <-- cluster coordinator (Raft)
|
[Alpha nodes] <-- data + query workers
sharded by predicate
each shard replicated 3x via Raft
|
[Storage engine]
Badger LSM (Go, RocksDB-like)
|
Horizontal scale:
add more Alphas, Zero auto-balancesSelf-Hosting & Configuration
# docker-compose.yml — 3-alpha HA cluster
version: "3.8"
services:
zero:
image: dgraph/dgraph:v23.1
command: dgraph zero --my=zero:5080
ports: ["5080:5080", "6080:6080"]
alpha1:
image: dgraph/dgraph:v23.1
command: dgraph alpha --my=alpha1:7080 --zero=zero:5080
ports: ["8080:8080", "9080:9080"]
alpha2:
image: dgraph/dgraph:v23.1
command: dgraph alpha --my=alpha2:7080 --zero=zero:5080
ports: ["8081:8080", "9081:9080"]
alpha3:
image: dgraph/dgraph:v23.1
command: dgraph alpha --my=alpha3:7080 --zero=zero:5080
ports: ["8082:8080", "9082:9080"]# Auth example: only show posts owned by the logged-in user
type Post @auth(
query: { rule: "query($USER: String!) { queryPost { author { name(eq: $USER) } } }" }
) {
id: ID!
title: String!
author: Person!
}Key Features
- Native GraphQL — schema-first API, no resolver boilerplate
- DQL — Dgraph Query Language for advanced traversals
- ACID transactions — distributed, Raft-replicated
- Horizontal scale — predicates sharded across Alpha nodes
- Full-text + geo indexes — search + spatial queries in-engine
- @auth rules — row-level authorization in GraphQL directives
- Cloud + self-hosted — Dgraph Cloud or Kubernetes/Docker
- Go implementation — single binary, easy ops
Comparison with Similar Tools
| Feature | Dgraph | Neo4j | ArangoDB | JanusGraph | TigerGraph |
|---|---|---|---|---|---|
| Query language | GraphQL + DQL | Cypher | AQL | Gremlin | GSQL |
| Distributed | Yes (native) | Cluster (AuraDB) | Yes (native) | Backend-dependent | Yes (commercial) |
| License | Apache-2.0 | GPLv3 / Commercial | Apache-2.0 | Apache-2.0 | Commercial |
| Schema style | GraphQL | Optional | Multi-model | Schema-less | Fixed schema |
| Full-text | Built-in | Plugin | Built-in | External (ES) | Built-in |
| Best For | GraphQL-first apps | OLTP graph + Cypher shops | Multi-model + graph | Legacy/huge graphs | Enterprise analytics |
FAQ
Q: Dgraph vs Neo4j? A: Neo4j is the graph database incumbent with a vast Cypher ecosystem and mature tooling. Dgraph is distributed by design and GraphQL-native. Pick Neo4j for graph-heavy OLTP where Cypher is a plus; Dgraph when GraphQL and horizontal scale matter.
Q: Is Dgraph truly open source? A: Yes, Apache-2.0 for the core. Some enterprise features (binary/ACL backups, audit logging) require a paid license. Dgraph Cloud is a managed option.
Q: How does Dgraph scale? A: Data is sharded by predicate across Alpha nodes. Add more Alphas and Zero rebalances predicates automatically. Raft replication across 3 nodes gives HA per shard.
Q: Does Dgraph have a managed option? A: Yes, Dgraph Cloud (hypermodernized serverless GraphQL backend). Or self-host on Kubernetes — the Helm chart and Docker Compose examples cover most needs.
Sources
- GitHub: https://github.com/dgraph-io/dgraph
- Docs: https://dgraph.io/docs
- Company: Hypermode (acquired Dgraph)
- License: Apache-2.0