Overview
This guide covers production deployment strategies for the Groq Microservice, including process management, containerization, environment security, monitoring, and cloud deployment options.Pre-Deployment Checklist
Before deploying to production, ensure you’ve completed these steps:Environment Variables
✅ Production
.env file configured with valid GROQ_API_KEY✅ Port configured appropriately (typically 3000, 5055, or behind reverse proxy)✅ .env file excluded from version control (verify .gitignore)Dependencies
✅ All production dependencies installed✅ No dev dependencies in production bundle✅
package-lock.json committed to ensure consistent installsCode Quality
✅ Error handling tested for API failures✅ CORS configured for production domains only✅ Request size limits appropriate for your use case
Process Management with PM2
PM2 is a production-grade process manager for Node.js applications. It ensures your service stays running, restarts on crashes, and provides monitoring capabilities.Installing PM2
Install PM2 globally with the
-g flag so it’s available system-wide.Basic PM2 Deployment
Configure Auto-Start on System Reboot
startup command generates a startup script for your system, and save persists the current process list.PM2 Ecosystem File (Recommended)
Create aecosystem.config.js file in your project root for advanced configuration:
ecosystem.config.js
Configuration Options Explained
Configuration Options Explained
- instances: Number of processes (use
'max'for CPU count) - exec_mode:
'cluster'for load balancing across instances - env: Environment variables (API key should still be in
.envfile) - error_file/out_file: Log file locations
- autorestart: Automatically restart on crashes
- max_memory_restart: Restart if memory exceeds threshold
- watch: Enable to restart on file changes (disable in production)
PM2 Management Commands
Docker Deployment
Containerizing your application with Docker ensures consistent environments across development, staging, and production.Dockerfile
Create aDockerfile in your project root:
Dockerfile
Docker Compose (Optional)
Createdocker-compose.yml for easier management:
docker-compose.yml
Building and Running
Docker Management Commands
Environment Variable Security
Protecting your API keys and sensitive configuration is critical for production deployments.Best Practices
1. Never Commit .env Files
1. Never Commit .env Files
Verify your Check git status to ensure
.gitignore excludes environment files:.gitignore
.env is ignored:2. Use Environment-Specific Files
2. Use Environment-Specific Files
Maintain separate environment files:Store production
.env on the server only, never in version control.3. Restrict File Permissions
3. Restrict File Permissions
On Linux/Unix servers, restrict
.env file access:4. Use Secret Management Services
4. Use Secret Management Services
For enhanced security, use dedicated secret management:Cloud Providers:
- AWS Secrets Manager
- Google Cloud Secret Manager
- Azure Key Vault
- HashiCorp Vault
- Docker Secrets (Swarm mode)
- Kubernetes Secrets
5. Rotate API Keys Regularly
5. Rotate API Keys Regularly
Implement a key rotation schedule:
- Generate new API key in Groq console
- Update
.envfile with new key - Restart service:
pm2 restart groq-micro - Verify service is working
- Revoke old key in Groq console
6. Audit and Monitor
6. Audit and Monitor
- Enable API usage monitoring in Groq console
- Set up alerts for unusual activity
- Log API errors (without exposing keys)
- Review access logs regularly
Reverse Proxy Configuration
In production, run your Node.js service behind a reverse proxy (nginx or Apache) for SSL termination, load balancing, and security.Nginx Configuration
/etc/nginx/sites-available/groq-micro
Use Certbot to automatically obtain and renew free SSL certificates from Let’s Encrypt.
Cloud Platform Deployments
AWS (Elastic Beanstalk)
Google Cloud Run
Digital Ocean App Platform
- Connect your Git repository
- Select Node.js as runtime
- Set build command:
npm install - Set run command:
node server.js - Add environment variable:
GROQ_API_KEY - Deploy
Heroku
Monitoring and Logging
Application Logging
Enhance the server with structured logging:Health Check Endpoint
Add a health check endpoint for monitoring:server.js
Monitoring Services
PM2 Plus
PM2 Plus
Real-time monitoring for PM2-managed applications:Provides dashboards, alerts, and performance metrics.
New Relic
New Relic
APM solution for Node.js:Follow New Relic setup for Node.js applications.
DataDog
DataDog
Infrastructure and application monitoring:Configure DataDog agent on your server.
Sentry
Sentry
Error tracking and monitoring:Initialize Sentry in your application for error tracking.
Performance Optimization
Enable Compression
Rate Limiting
Request Timeout
Backup and Disaster Recovery
Backup Strategy
- Store
.envfile in secure password manager - Document all environment variables
- Keep infrastructure as code (Docker, terraform)
- Regular code backups in version control
Security Hardening
Use Helmet.js
Use Helmet.js
Implement Authentication
Implement Authentication
Add API key authentication for your endpoint:
Input Validation
Input Validation
Troubleshooting Production Issues
Service Won't Start
Service Won't Start
Check logs:Common issues:
- Missing
GROQ_API_KEYin environment - Port already in use
- Insufficient permissions
- Node.js version mismatch
API Requests Failing
API Requests Failing
- Verify Groq API key is valid
- Check Groq API status
- Review error logs for details
- Test with curl directly
- Verify network connectivity
High Memory Usage
High Memory Usage
Slow Response Times
Slow Response Times
- Check Groq API latency
- Review LLM model choice (8b-instant vs 70b-versatile)
- Monitor CPU usage
- Consider scaling to multiple instances
Next Steps
- Review Configuration Guide for customization options
- Check API Reference for endpoint documentation
- Explore Setup Guide for development environment