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

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:
# 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

#!/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”
Render Web Service
  1. Connect Repository: Connect your Git repository containing the Dockerfile
Render Git
  1. 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)
Render Configure
  1. 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)
Render Instance Type
  1. 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 Render Environment Variable
  1. Deploy
Deployed Render

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

# 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:
# 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:
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:
# In render.yaml
healthCheckPath: /health

Logging

Access logs via Render dashboard or using their CLI:
# 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:
# 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:
# 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