Dgraph Graph Database
Dgraph distributed graph database with Ratel UI.
Overview
Dgraph is a horizontally scalable and distributed graph database written in Go, designed to handle complex graph queries with native GraphQL support and a SQL-like query language called GraphQL+-. The database architecture separates concerns through specialized components: dgraph-zero acts as the cluster orchestrator managing metadata, group membership, and transaction timestamps, while dgraph-alpha serves as the data node handling actual graph storage and query processing. This configuration includes Ratel, Dgraph's web-based UI that provides an intuitive interface for schema management, data exploration, and query execution with real-time visualization of graph relationships.
The three-component stack creates a production-ready distributed graph database where dgraph-zero coordinates the cluster state and dgraph-alpha processes queries against the actual graph data, while Ratel offers a powerful administrative interface for database operations. Unlike traditional relational databases, this setup excels at handling complex interconnected data with multi-hop traversals, making relationship queries that would require expensive JOINs in SQL databases execute efficiently through native graph algorithms. The distributed architecture allows horizontal scaling by adding more alpha nodes while maintaining ACID compliance and strong consistency across the cluster.
Data engineers working with knowledge graphs, recommendation engines, and fraud detection systems will find this stack particularly valuable, as will developers building social networks, IoT device management platforms, and any application requiring complex relationship modeling. The combination of native GraphQL support, distributed architecture, and the intuitive Ratel interface makes this configuration ideal for teams transitioning from traditional databases to graph-based solutions, or organizations needing to scale existing graph workloads across multiple nodes while maintaining query performance and data consistency.
Key Features
- Native GraphQL and GraphQL+- query language support with automatic schema inference
- Horizontal scaling through dgraph-alpha node replication with automatic sharding
- ACID transaction compliance with distributed consensus using Raft protocol
- Real-time graph visualization and query execution through Ratel web interface
- Multi-version concurrency control enabling consistent reads during writes
- Built-in full-text search with configurable analyzers and tokenizers
- Automatic background compaction and garbage collection for optimal storage
- Type system with predicate-based schema validation and indexing strategies
Common Use Cases
- 1Social networking platforms requiring friend-of-friend recommendations and social graph analysis
- 2E-commerce recommendation engines analyzing user behavior and product relationships
- 3Fraud detection systems tracking complex transaction patterns and entity connections
- 4Knowledge management platforms organizing interconnected documents and concepts
- 5IoT device networks modeling sensor relationships and data flow dependencies
- 6Supply chain management tracking product origins and distribution networks
- 7Content management systems with complex taxonomies and cross-referenced articles
Prerequisites
- Minimum 4GB RAM allocation for dgraph-alpha with additional memory for large datasets
- Docker Engine 20.10+ with Docker Compose v2 support for proper networking
- Available ports 5080, 6080, 8000, 8080, and 9080 for inter-service communication
- Basic understanding of graph database concepts and GraphQL query syntax
- SSD storage recommended for optimal query performance and data persistence
- Network connectivity allowing container-to-container communication on bridge network
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 zero: 3 image: dgraph/dgraph:latest4 container_name: dgraph-zero5 restart: unless-stopped6 volumes: 7 - dgraph_zero:/dgraph8 ports: 9 - "5080:5080"10 - "6080:6080"11 command: dgraph zero --my=zero:508012 networks: 13 - dgraph-network1415 alpha: 16 image: dgraph/dgraph:latest17 container_name: dgraph-alpha18 restart: unless-stopped19 volumes: 20 - dgraph_alpha:/dgraph21 ports: 22 - "${ALPHA_PORT:-8080}:8080"23 - "9080:9080"24 command: dgraph alpha --my=alpha:7080 --zero=zero:5080 --security whitelist=0.0.0.0/025 depends_on: 26 - zero27 networks: 28 - dgraph-network2930 ratel: 31 image: dgraph/ratel:latest32 container_name: dgraph-ratel33 restart: unless-stopped34 ports: 35 - "${RATEL_PORT:-8000}:8000"36 networks: 37 - dgraph-network3839volumes: 40 dgraph_zero: 41 dgraph_alpha: 4243networks: 44 dgraph-network: 45 driver: bridge.env Template
.env
1# Dgraph2ALPHA_PORT=80803RATEL_PORT=8000Usage Notes
- 1Ratel UI at http://localhost:8000
- 2Alpha API at http://localhost:8080
- 3GraphQL support built-in
- 4Native distributed graph
Individual Services(3 services)
Copy individual services to mix and match with your existing compose files.
zero
zero:
image: dgraph/dgraph:latest
container_name: dgraph-zero
restart: unless-stopped
volumes:
- dgraph_zero:/dgraph
ports:
- "5080:5080"
- "6080:6080"
command: dgraph zero --my=zero:5080
networks:
- dgraph-network
alpha
alpha:
image: dgraph/dgraph:latest
container_name: dgraph-alpha
restart: unless-stopped
volumes:
- dgraph_alpha:/dgraph
ports:
- ${ALPHA_PORT:-8080}:8080
- "9080:9080"
command: dgraph alpha --my=alpha:7080 --zero=zero:5080 --security whitelist=0.0.0.0/0
depends_on:
- zero
networks:
- dgraph-network
ratel
ratel:
image: dgraph/ratel:latest
container_name: dgraph-ratel
restart: unless-stopped
ports:
- ${RATEL_PORT:-8000}:8000
networks:
- dgraph-network
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 zero:5 image: dgraph/dgraph:latest6 container_name: dgraph-zero7 restart: unless-stopped8 volumes:9 - dgraph_zero:/dgraph10 ports:11 - "5080:5080"12 - "6080:6080"13 command: dgraph zero --my=zero:508014 networks:15 - dgraph-network1617 alpha:18 image: dgraph/dgraph:latest19 container_name: dgraph-alpha20 restart: unless-stopped21 volumes:22 - dgraph_alpha:/dgraph23 ports:24 - "${ALPHA_PORT:-8080}:8080"25 - "9080:9080"26 command: dgraph alpha --my=alpha:7080 --zero=zero:5080 --security whitelist=0.0.0.0/027 depends_on:28 - zero29 networks:30 - dgraph-network3132 ratel:33 image: dgraph/ratel:latest34 container_name: dgraph-ratel35 restart: unless-stopped36 ports:37 - "${RATEL_PORT:-8000}:8000"38 networks:39 - dgraph-network4041volumes:42 dgraph_zero:43 dgraph_alpha:4445networks:46 dgraph-network:47 driver: bridge48EOF4950# 2. Create the .env file51cat > .env << 'EOF'52# Dgraph53ALPHA_PORT=808054RATEL_PORT=800055EOF5657# 3. Start the services58docker compose up -d5960# 4. View logs61docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/dgraph-graph-database/run | bashTroubleshooting
- Error 'zero server is not ready': Wait 30-60 seconds for dgraph-zero initialization before alpha connection attempts
- Ratel UI shows 'Connection failed': Verify dgraph-alpha is accessible at localhost:8080 and check firewall settings
- Query timeout errors: Increase memory allocation for dgraph-alpha or add query complexity limits in schema
- Port binding conflicts: Modify ALPHA_PORT and RATEL_PORT environment variables if default ports are occupied
- Data persistence issues: Ensure Docker volumes dgraph_zero and dgraph_alpha have proper write permissions
- High memory usage during imports: Use chunked data loading through live loader or bulk loader utilities
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Components
dgraph-zerodgraph-alphadgraph-ratel
Tags
#dgraph#graph#distributed#graphql#nosql
Category
Database StacksAd Space
Shortcuts: C CopyF FavoriteD Download