# Source: https://docs.hypermode.com/dgraph/self-managed/render.md

# Deploy Dgraph on Render

> Complete guide to self-hosting Dgraph standalone on Render with persistent storage and production configurations.

# Dgraph Standalone Deployment On Render Guide

This guide walks you through deploying Dgraph as a self-hosted solution on Render using the Dgraph standalone Docker image.

## Prerequisites

* A Render account (free tier available)
* Basic familiarity with Docker
* Git repository for your deployment configuration

## Overview

Dgraph is a distributed graph database that can be deployed in standalone mode for development and smaller production workloads. Render's container service provides an excellent platform for hosting Dgraph with persistent storage.

## Step 1: Prepare Your Repository

Create a new Git repository with the following structure:

```
dgraph-render/
├── Dockerfile
├── dgraph-config.yml
├── start.sh
└── README.md
```

### Create the Dockerfile

```dockerfile
FROM dgraph/standalone:latest

# Create directories for data and config
RUN mkdir -p /dgraph/data /dgraph/config

# Copy configuration files
COPY dgraph-config.yml /dgraph/config

# Set working directory
WORKDIR /dgraph

# Expose the Dgraph ports
EXPOSE 8080 9080 8000

# Start Dgraph in standalone mode
ADD start.sh /
RUN chmod +x /start.sh

CMD ["/start.sh"]
```

### Create the Configuration File

Create `dgraph-config.yml`:

```yaml
# Dgraph configuration for standalone deployment

datadir: /dgraph/data
bindall: true

# HTTP & GRPC ports
port_offset: 0
grpc_port: 9080
http_port: 8080

# Alpha configuration
alpha:
  lru_mb: 1024

# Security settings (adjust as needed)
whitelist: 0.0.0.0/0

# Logging
logtostderr: true
v: 2

# Performance tuning for cloud deployment
badger:
  compression: snappy
  numgoroutines: 8
```

## Create start.sh

```bash
#!/bin/bash

# Start Dgraph Zero
dgraph zero --config /dgraph/config/dgraph-config.yml &

# Start Dgraph Alpha
dgraph alpha --config /dgraph/config/dgraph-config.yml &

# Wait for all processes to finish
wait
```

## Step 2: Deploy to Render

### Using the Render Dashboard

1. **Login to Render** and click "New +" → "Web Service"

<img src="https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-web-service.png?fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=f28235bc1970f4e1ca0b6dbfea155c9d" alt="Render Web Service" width="2782" height="1386" data-path="images/dgraph/guides/render/render-web-service.png" srcset="https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-web-service.png?w=280&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=5dd5204a9d6421bbcdceadb4d3c2d7d2 280w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-web-service.png?w=560&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=44b003c75a9c31e49381a0171fb4a140 560w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-web-service.png?w=840&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=8cefd21914118245b91a43f2be974078 840w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-web-service.png?w=1100&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=8c1c56e9ed41fce19fbec87b61c1ad5a 1100w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-web-service.png?w=1650&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=e721da47ecc7089230c4f462e890f85c 1650w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-web-service.png?w=2500&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=350d92c6c900f49b8e4e19bdd7272896 2500w" data-optimize="true" data-opv="2" />

2. **Connect Repository**: Connect your Git repository containing the Dockerfile

<img src="https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-git.png?fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=903fe81cc5a9a3ff73cd809b78657c8d" alt="Render Git" width="2786" height="940" data-path="images/dgraph/guides/render/render-git.png" srcset="https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-git.png?w=280&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=d774f51f8954c6497f170b3fa6d19706 280w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-git.png?w=560&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=1cdc8a2022d790f662fda19bf4f6ddc8 560w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-git.png?w=840&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=d0733c4e58a92610286b872c91e00c05 840w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-git.png?w=1100&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=8b2f70a72fdc64b94093ec131377f63c 1100w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-git.png?w=1650&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=d32cc6e45d28a0e3c64f9dac584f1c27 1650w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-git.png?w=2500&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=fc4eb7e0e3144de17defeceed55c902f 2500w" data-optimize="true" data-opv="2" />

3. **Configure Service Settings**:
   * **Name**: `dgraph-standalone`
   * **Region**: Choose your preferred region
   * **Branch**: `main` (or your default branch)
   * **Runtime**: `Docker`
   * **Build Command**: Leave empty (Docker handles this)
   * **Start Command**: Leave empty (handled by Dockerfile CMD)

<img src="https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-configure.png?fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=839105cc781d09b582f22613ab72ed56" alt="Render Configure" width="2780" height="2376" data-path="images/dgraph/guides/render/render-configure.png" srcset="https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-configure.png?w=280&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=53f9a8a83291d789766f41ac558e0049 280w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-configure.png?w=560&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=1191f1171fcf9ddf41d771e092d634b0 560w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-configure.png?w=840&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=6b5ec5ae229567859cc79df13956effb 840w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-configure.png?w=1100&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=1fe5e3217b426966c7ff9e43350ca79d 1100w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-configure.png?w=1650&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=fe67cbdeffa90fdcc04ff84ad9fc4672 1650w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-configure.png?w=2500&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=7fc1f5a4dac10c3b1d1513e49b72dad1 2500w" data-optimize="true" data-opv="2" />

4. **Environment Settings**:
   * **Instance Type**: Choose based on your needs (Starter for testing, Standard+ for production)
   * **Scaling**: Set to 1 instance (Dgraph standalone doesn't support horizontal scaling)

<img src="https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-instance-type.png?fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=11c197cc101dc34d2400da421c0938c5" alt="Render Instance Type" width="2698" height="1184" data-path="images/dgraph/guides/render/render-instance-type.png" srcset="https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-instance-type.png?w=280&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=37078e52babf2d85ac858424cee7e9b8 280w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-instance-type.png?w=560&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=61a4b9c1c397fd280f16842e67e4e614 560w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-instance-type.png?w=840&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=eeb76119d8e1350d5e2da75cb427c6b9 840w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-instance-type.png?w=1100&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=0b3c4cecf849acf04c7fb64464b48d42 1100w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-instance-type.png?w=1650&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=82769eb6ebb4dd878d4ac7b3bd3ddaa8 1650w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-instance-type.png?w=2500&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=b2c7044f8bbb1a5b71fe4cb49f4f191f 2500w" data-optimize="true" data-opv="2" />

5. Set `PORT` environment variable

Our Render application exposes a single port which we must specify in an environment variable. We'll expose Dgraph's HTTP port 8080 by setting the `PORT` environment variable to 8080

<img src="https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-env-var.png?fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=25d0026312f70e9a53c9d7661f2af52f" alt="Render Environment Variable" width="2016" height="1004" data-path="images/dgraph/guides/render/render-env-var.png" srcset="https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-env-var.png?w=280&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=384f680a85e9285e382755c5b056fa0e 280w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-env-var.png?w=560&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=b38ed1ee248fcfce229c73a6b74f6948 560w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-env-var.png?w=840&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=75f3a58ac36da94c12424c6b2597e68c 840w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-env-var.png?w=1100&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=8c33c9a118cab9a7bff02e0b3336a792 1100w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-env-var.png?w=1650&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=d25d1813e5d89d1908a36018b4b8ff55 1650w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/render-env-var.png?w=2500&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=90f5e610299be8329ea9f9aa747c0030 2500w" data-optimize="true" data-opv="2" />

6. Deploy

<img src="https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/dgraph-render-deploy.png?fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=b7417c31d7af8b7000766bb1b8d155d3" alt="Deployed Render" width="2792" height="2694" data-path="images/dgraph/guides/render/dgraph-render-deploy.png" srcset="https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/dgraph-render-deploy.png?w=280&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=0eaa831813114f530845d5dfcca6fb33 280w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/dgraph-render-deploy.png?w=560&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=4307f73e128a048587237f47c5afbce9 560w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/dgraph-render-deploy.png?w=840&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=dfee77403fa37d1a8c130aa751171b5c 840w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/dgraph-render-deploy.png?w=1100&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=5144a9ddbc55b007ff97cff27f3a1ee9 1100w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/dgraph-render-deploy.png?w=1650&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=822f827d7a1eef57c378096b553e06a4 1650w, https://mintcdn.com/hypermode/dXxqSmbeZl0pqUKt/images/dgraph/guides/render/dgraph-render-deploy.png?w=2500&fit=max&auto=format&n=dXxqSmbeZl0pqUKt&q=85&s=c9f7f4243e2a4d3d9ead3e2bcc6a7258 2500w" data-optimize="true" data-opv="2" />

## Step 3: Configure Persistent Storage

Render provides persistent disks for data storage:

1. **In Dashboard**: Go to your service → "Settings" → "Disks"

2. **Add Disk**:
   * **Name**: `dgraph-data`
   * **Mount Path**: `/dgraph/data`
   * **Size**: Start with 10GB, scale as needed

3. **Redeploy** your service to apply disk changes

## Step 4: Access Your Dgraph Instance

Once deployed, your Dgraph instance will be available at: `https://your-service-name.onrender.com`

## Step 5: Initial Setup and Testing

### Test the Connection

```bash
# Health check
curl https://your-service-name.onrender.com:8080/health

# State endpoint
curl https://your-service-name.onrender.com:8080/state
```

## Security Considerations

### 1. Authentication Setup

For production deployments, enable authentication:

```yaml
# Add to dgraph-config.yml
security:
  whitelist: "your-allowed-ips/32"
  
# Enable ACLs (Access Control Lists)
acl:
  enabled: true
  secret_file: "/dgraph/config/hmac_secret"
```

### 2. Environment Variables

Set sensitive configuration via Render environment variables:

```bash
DGRAPH_ALPHA_SECURITY_WHITELIST=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
DGRAPH_ALPHA_ACL_SECRET_FILE=/dgraph/config/hmac_secret
```

### 3. Network Security

* Use Render's private networking for internal communication
* Configure proper firewall rules in your application
* Consider using Render's built-in SSL termination

## Monitoring and Maintenance

### Health Checks

Render automatically monitors your service. Configure custom health checks:

```yaml
# In render.yaml
healthCheckPath: /health
```

### Logging

Access logs via Render dashboard or using their CLI:

```bash
# Install Render CLI
npm install -g @render-com/cli

# View logs
render logs -s your-service-id
```

### Backups

Implement regular backups using Dgraph's export feature:

```bash
# Create backup script
#!/bin/bash
curl -X POST https://your-service-name.onrender.com:8080/admin/export

# Schedule via cron job or external service
```

## Scaling Considerations

### Vertical Scaling

* Monitor memory and CPU usage in Render dashboard
* Upgrade instance type as needed
* Increase disk size for growing datasets

### Performance Tuning

Optimize your `dgraph-config.yml`:

```yaml
# For better performance on Render
alpha:
  lru_mb: 2048  # Adjust based on instance memory
  
badger:
  compression: snappy
  numgoroutines: 16
  
# Connection limits
grpc:
  max_message_size: 4194304  # 4MB
```

## Troubleshooting

### Common Issues

1. **Service Won't Start**:
   * Check Dockerfile syntax
   * Verify port configuration
   * Review logs in Render dashboard

2. **Data Persistence Issues**:
   * Ensure disk is properly mounted
   * Check disk space usage
   * Verify write permissions

3. **Connection Problems**:
   * Confirm port bindings (8080, 9080)
   * Check firewall/security settings
   * Verify service URL

## Resources

* [Dgraph Documentation](https://dgraph.io/docs/)
* [Render Documentation](https://render.com/docs)
* [Dgraph Docker Hub](https://hub.docker.com/r/dgraph/dgraph)
* [GraphQL Schema Reference](https://dgraph.io/docs/graphql/schema/)