A complete infrastructure deployment for Dgraph and sentence embeddings on Render.com.
This project deploys a microservices architecture with two main components:
- Embeddings Service - REST API for generating sentence embeddings using Sentence Transformers
- Dgraph Database - Graph database service for storing and querying connected data
A Flask-based REST API that provides sentence embeddings using the all-MiniLM-L6-v2
model.
Features:
- 🔐 API key authentication
- 🌐 CORS enabled for web applications
- 📊 Multiple input formats (map-based and KServe-compatible)
- 🏥 Health monitoring endpoints
- ⚡ Optimized for fast inference
Key Endpoints:
GET /health
- Service health checkPOST /embedding
- Generate embeddings (requires API key)GET /api-key-info
- API key usage information
A standalone Dgraph instance for graph database operations.
Features:
- 💾 Persistent storage (10GB disk)
- 🔧 Standalone configuration
- 🌐 GraphQL and admin interfaces
- 📈 Monitoring and health checks
Key Endpoints:
- GraphQL interface at
/graphql
- Admin UI at port 8080
- Health check at
/health
infra/
├── README.md # This file
├── render.yaml # Render deployment configuration
├── embeddings/ # Embeddings service
│ ├── app.py # Flask application
│ ├── requirements.txt # Python dependencies
│ ├── Dockerfile # Container configuration
│ ├── getmodels.py # Model pre-download script
│ ├── test_api.py # API testing script
│ └── README.md # Service-specific documentation
└── render-dgraph/ # Dgraph database service
├── Dockerfile # Container configuration
├── dgraph-config.yml # Dgraph configuration
├── start.sh # Startup script
└── README.md # Service-specific documentation
- GitHub account
- Render account
- Git repository with this code
- Push to GitHub: Ensure your code is in a GitHub repository
- Create Blueprint: In Render Dashboard, create a new Blueprint
- Connect Repository: Link your GitHub repository
- Auto-Deploy: Render will automatically detect
render.yaml
and deploy both services
Deploy each service individually through the Render Dashboard:
- Create two Web Services
- Configure each service according to the settings in
render.yaml
- Deploy and monitor
The render.yaml
file defines the complete infrastructure:
services:
- type: web
name: embeddings
runtime: docker
rootDir: embeddings/
healthCheckPath: /health
# ... additional configuration
- type: web
name: dgraph-standalone
runtime: docker
rootDir: render-dgraph/
healthCheckPath: /health
# ... additional configuration
Variable | Description | Default | Required |
---|---|---|---|
API_KEY |
Authentication key | Auto-generated | Recommended |
SHOW_API_KEY_INFO |
Show key in info endpoint | false |
No |
TRANSFORMERS_CACHE |
Model cache directory | /tmp/transformers_cache |
No |
Variable | Description | Default | Required |
---|---|---|---|
PORT |
Server port | 8080 |
Yes |
DGRAPH_ALPHA_BINDALL |
Allow all IP connections | true |
Yes |
DGRAPH_ALPHA_WHITELIST |
IP whitelist | 0.0.0.0/0 |
Yes |
- Dgraph Data: 10GB persistent disk mounted at
/dgraph/data
- Model Cache: Temporary storage for ML models
- Set SSH in Render
- Get the Service SSH connecion string ( click CONNECT > SSH)
- Use SCP to copy the exported files to the Render disk
scp ~/Downloads/pyp-export/* [email protected]:/dgraph/data/export
- Use dgraph live or bulk from the Render machine From Render, Connect and use the terminal or use ssh.
dgraph live -c 1 -f export/g01.rdf -s export/g01.schema -t "<token used in dgraph alpha>"
# Health check
curl https://your-embeddings-service.onrender.com/health
# Get API key (if SHOW_API_KEY_INFO=true)
curl https://your-embeddings-service.onrender.com/api-key-info
# Generate embeddings
curl -X POST https://your-embeddings-service.onrender.com/embedding \
-H "Content-Type: application/json" \
-H "X-Api-Key: YOUR_API_KEY" \
-d '{"text1": "Hello world", "text2": "How are you?"}'
# Health check
curl https://your-dgraph-service.onrender.com/health
# State endpoint
curl https://your-dgraph-service.onrender.com/state
Both services provide health check endpoints for monitoring:
- Monitor service status through Render Dashboard
- Set up alerts for service downtime
- Check logs for performance metrics
- Embeddings: ~2GB RAM for model loading
- Dgraph: Varies based on data size (10GB disk allocated)
- CPU: Optimized for single-worker configurations
- API key authentication required for embedding endpoints
- CORS configured for web application access
- Environment-based configuration for sensitive data
For production use:
- Restrict
DGRAPH_ALPHA_WHITELIST
to specific IP ranges - Enable Dgraph authentication and ACLs
- Use environment variables for sensitive configuration
- Regular security updates
- First Request: 30-60 seconds (model loading)
- Subsequent Requests: <1 second
- Concurrency: Single worker recommended
- Timeout: 120 seconds configured
- Scaling: Vertical scaling only (standalone mode)
- Storage: 10GB persistent disk
- Backup: Manual backup procedures recommended
cd embeddings/
pip install -r requirements.txt
python getmodels.py # Pre-download model (optional)
python app.py # Start development server
cd render-dgraph/
docker build -t dgraph-local .
docker run -p 8080:8080 -p 9080:9080 dgraph-local
- Embeddings Service Documentation - Detailed API documentation
- Dgraph Service Documentation - Database setup and configuration
- Render Documentation - Platform-specific guides
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is open source and available under the MIT License.
-
Model Download Failures
- Check internet connectivity
- Verify Hugging Face Hub access
- Pre-download models locally
-
Memory Issues
- Reduce request batch sizes
- Monitor service logs
- Consider upgrading service tier
-
Deployment Failures
- Check
render.yaml
syntax - Verify Dockerfile configurations
- Review build logs in Render Dashboard
- Check
-
Database Connection Issues
- Verify Dgraph service is running
- Check port configurations
- Review whitelist settings
- Check service logs in Render Dashboard
- Review individual service README files
- Open an issue in this repository
- Contact Render support for platform-specific issues