---
title: "Deploy Dgraph"
description: "Dgraph 25 graph database with Zero, Alpha and token-auth gateway."
category: "Storage"
url: https://railway.com/deploy/dgraph
---

# Deploy Dgraph

Dgraph 25 graph database with Zero, Alpha and token-auth gateway.

**[Deploy Dgraph on Railway](https://railway.com/template/dgraph)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/dgraph/manifest.json

- **Creator:** Agaz Self-Host
- **Category:** Storage

## Template content

### gateway https://raw.githubusercontent.com/caddyserver/website/5c921006aae4feb2184782ae528c2bb09a07e04f/src/resources/images/favicon.png

- **Image:** caddy:2.11.4-alpine
- **Start command:** `sh -c 'printf "%s\n" "$CADDYFILE" > /tmp/Caddyfile && exec caddy run --config /tmp/Caddyfile --adapter caddyfile'`
- **Health check:** /healthz
- **Public domain:** Yes

### zero https://github.com/dgraph-io.png

- **Image:** dgraph/dgraph:v25.4.1
- **Start command:** `sh -c 'exec dgraph zero --my="$DGRAPH_ZERO_MY" --wal /dgraph/zw'`
- **Health check:** /health

### alpha https://github.com/dgraph-io.png

- **Image:** dgraph/dgraph:v25.4.1
- **Start command:** `sh -c 'exec dgraph alpha --my="$DGRAPH_ALPHA_MY" --zero="$DGRAPH_ZERO_ADDR" --postings /dgraph/p --wal /dgraph/w --tmp /dgraph/t --security "token=$DGRAPH_ADMIN_TOKEN; whitelist=0.0.0.0/0,::/0"'`
- **Health check:** /health

## Documentation

# Deploy and Host Dgraph on Railway

Dgraph is a distributed, open-source graph database with a native GraphQL API and its own query language, DQL. It stores data as a graph of nodes and edges, supports full-text, geo and vector indexes, and runs fast traversals and joins, which suits social graphs, knowledge graphs and recommendation engines.

## About Hosting Dgraph

This template deploys Dgraph v25.4.1 as a Zero node, which runs cluster coordination, and an Alpha node, which stores and serves data, each with its own Railway volume, plus a Caddy gateway as the public entry point. The gateway requires a bearer token and removes it before forwarding. Schema changes and other admin operations additionally need the Alpha admin token in the `X-Dgraph-AuthToken` header. Data survived redeploys of both nodes in testing. The gRPC API stays private. Memory use grows with dataset size; start on Hobby and scale up. Back up both volumes regularly.

## Common Use Cases

- Knowledge graphs and recommendation engines with deep traversals
- A GraphQL backend generated from a schema, without writing resolvers
- Social graphs, access graphs and fraud detection with DQL

## Dependencies for Dgraph Hosting

- `dgraph/dgraph:v25.4.1` (official image) for Zero and Alpha, each with a volume at `/dgraph`
- `caddy:2.11.4-alpine` (official image) as the token gateway

### Deployment Dependencies

- [Dgraph documentation](https://docs.dgraph.io/)
- [Dgraph v25.4.1 release](https://github.com/hypermodeinc/dgraph/releases/tag/v25.4.1)
- [Dgraph client libraries](https://docs.dgraph.io/clients/)
- [Railway volumes](https://docs.railway.com/reference/volumes)

### Implementation Details

| Service | Image | Networking | Storage |
| --- | --- | --- | --- |
| zero | `dgraph/dgraph:v25.4.1` | private only (5080, 6080) | volume at `/dgraph` |
| alpha | `dgraph/dgraph:v25.4.1` | private: HTTP 8080, gRPC 9080 | volume at `/dgraph` |
| gateway | `caddy:2.11.4-alpine` | public domain on 8080 | none |

```bash
# GraphQL schema (admin)
curl -X POST "$DGRAPH_URL/admin/schema" -H "Authorization: Bearer $DGRAPH_API_TOKEN" \
  -H "X-Dgraph-AuthToken: $DGRAPH_ADMIN_TOKEN" --data-binary 'type Task { id: ID! title: String! @search(by: [term]) }'
# GraphQL
curl -X POST "$DGRAPH_URL/graphql" -H "Authorization: Bearer $DGRAPH_API_TOKEN" \
  -H "Content-Type: application/json" -d '{"query": "{ queryTask { title } }"}'
```

Services on Railway can use `${{alpha.DGRAPH_PRIVATE_HTTP}}` or gRPC `${{alpha.DGRAPH_PRIVATE_GRPC}}` without the gateway token.

| Variable | Service | Default | Purpose |
| --- | --- | --- | --- |
| `DGRAPH_API_TOKEN` | gateway | generated | Bearer token for all public requests |
| `DGRAPH_ADMIN_TOKEN` | alpha | generated | Required for admin operations |

Notes:

- RDF mutations must put each triple on its own line.
- Ratel, the old web UI, is not included; use any GraphQL client or the DQL HTTP API.

This is a community-maintained deployment package and does not imply affiliation with or endorsement by the Dgraph project or its maintainers.

## Why Deploy Dgraph on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Dgraph on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.


## Similar templates

- [Garage S3 Storage](https://railway.com/deploy/garage-s3-storage) — Ultra-light S3 server: fast, open-source, plug-and-play.
- [Redis](https://railway.com/deploy/redis-1) — Self Host Latest Redis with Railway
- [EasyImg](https://railway.com/deploy/easyimg) — Simple self-hostable Nuxt.js personal image hosting system.

Open this page in a browser: https://railway.com/deploy/dgraph
