Overview
This guide covers production deployment best practices for Duckling, including performance optimization, monitoring, backup strategies, and disaster recovery.Pre-Deployment Checklist
Security configured
-
ADMIN_PASSWORDchanged from default -
DUCKLING_API_KEYgenerated withopenssl rand -hex 32 -
SESSION_SECRETgenerated withopenssl rand -hex 32 -
JWT_SECRETset (or usingSESSION_SECRET) - Rate limiting enabled (
RATE_LIMIT_ENABLED=true)
Environment configured
-
NODE_ENV=production - MySQL connection string validated
- DuckDB path exists with proper permissions
- Data directory mounted as persistent volume
- Log directory configured
Automation enabled
-
AUTO_START_SYNC=true(automatic sync on boot) -
AUTO_BACKUP=true(daily backups) -
AUTO_RESTART=true(auto-recovery on failures) - S3 backups configured (for large databases)
Resources allocated
- Minimum 8GB RAM for production workloads
- 16GB+ RAM for large databases (>100GB)
- Sufficient disk space (2-3x source database size)
- Docker memory limits set
Deployment Architecture
Single Container (Recommended)
The production Dockerfile builds a single container that serves both the API and frontend:Multi-Instance (High Availability)
For high availability, run multiple Duckling instances behind a load balancer:Resource Allocation
Memory Guidelines
Minimum: 4GB RAM
Recommended: 8-16GB RAM
Recommended: 16-32GB RAMAlso increase Node.js heap size:
CPU Allocation
Disk Space
Estimate required disk space:- DuckDB database: 30-50% of MySQL source size (columnar compression)
- Backups: 7 days × database size (with
BACKUP_RETENTION_DAYS=7) - S3 restore buffer: 1× database size (temporary during restore)
- Logs: 1-10GB depending on
LOG_LEVEL
- DuckDB: ~80GB (40% compression)
- Local backups: 560GB (7 days × 80GB)
- S3 restore buffer: 80GB (temporary)
- Total: 720GB minimum
With S3 backups enabled, you can reduce local backup retention to save disk space.
Performance Optimization
Sync Configuration
For large databases (100GB+):Query Performance
Connection Pooling
Zero-Downtime Automation
Duckling includes automatic failsafe features enabled by default:Automatic Sync
Auto-starts on container boot (
AUTO_START_SYNC=true)- Incremental sync every 15 minutes
- Watermark-based tracking (no duplicates)
- Automatic error recovery with exponential backoff
Automatic Backups
Daily local backups (
AUTO_BACKUP=true)- Runs every 24 hours (
BACKUP_INTERVAL_HOURS=24) - Keeps 7 days of backups (
BACKUP_RETENTION_DAYS=7) - Automatic cleanup of old backups
- One-command restore:
POST /automation/restore
S3 cloud backups (configure per database)
- Automatic upload after each local backup when
s3.enabled=true - Client-side AES-256 encryption recommended
- Fast disaster recovery (download vs. re-sync from MySQL)
- Critical for large databases (200GB+)
Health Monitoring
Auto-restart on failures (
AUTO_RESTART=true)- Monitors connections every 60 seconds
- Auto-reconnects DuckDB and MySQL on failures
- Exponential backoff retry (up to 3 attempts)
- Auto-triggers sync to verify recovery
Storage Management
Automatic cleanup (
AUTO_CLEANUP=true)- DuckDB handles VACUUM and WAL cleanup automatically
- Runs every 24 hours (
CLEANUP_INTERVAL_HOURS=24) - No manual intervention required
Multi-Database Configuration
Duckling supports multiple isolated database replicas on a single server instance.Database Configuration File
Location:./data/databases.json
Managing Databases via API
S3 Backup Configuration
For production databases, configure S3 backups for disaster recovery.Why S3 Backups?
S3 Setup
1. Generate encryption key:S3-Compatible Providers
| Provider | Endpoint | Force Path Style |
|---|---|---|
| AWS S3 | (leave blank) | false |
| Cloudflare R2 | https://<account_id>.r2.cloudflarestorage.com | false |
| Backblaze B2 | https://s3.<region>.backblazeb2.com | false |
| DigitalOcean Spaces | https://<region>.digitaloceanspaces.com | false |
| MinIO (self-hosted) | https://minio.internal:9000 | true |
Encryption Options
| Mode | Security | Performance | Recommendation |
|---|---|---|---|
none | No encryption | Fastest | Development only |
sse-s3 | AWS-managed | Fast | Good for most cases |
sse-kms | AWS KMS + audit trail | ~1ms overhead | Compliance requirements |
client-aes256 | Client-side (best) | Streaming, no memory spike | Recommended for production |
client-aes256: Encryption key never leaves your server. Protects against compromised AWS credentials and bucket misconfiguration.
Monitoring
Health Checks
Metrics Endpoints
Log Management
Sentry Error Tracking
Backup & Disaster Recovery
Backup Strategy
Local Backups (automatic):- Created every 24 hours (
BACKUP_INTERVAL_HOURS=24) - Kept for 7 days (
BACKUP_RETENTION_DAYS=7) - Stored in
./data/backups/
- Uploaded after each local backup
- Encrypted with client-side AES-256
- No retention limit (managed by S3 lifecycle policies)
Manual Backup
Restore from Backup
From local backup:Disaster Recovery Plan
Scenario 1: Data corruption- Stop sync:
docker stop duckling - Restore from S3 backup (faster) or local backup
- Verify data integrity:
POST /sync/validate - Resume operations:
docker start duckling
- Provision new server
- Install Docker and pull Duckling image
- Mount backup volume or restore from S3
- Start container with same
.envconfiguration - Service resumes automatically
- Local backup restore: 5-30 minutes (depends on database size)
- S3 backup restore: 10-60 minutes (includes download time)
- Full resync from MySQL: Hours to days (200GB+ databases)
Reverse Proxy Setup
Nginx Configuration
Traefik Configuration
Scaling Considerations
Vertical Scaling (Single Instance)
Best for:- Single database replication
- <100GB databases
- <1000 queries/minute
- Node.js single-threaded execution
- DuckDB file locking (single writer)
Horizontal Scaling (Read Replicas)
Best for:- Read-heavy workloads
- Multiple geographic regions
-
1000 queries/minute
Security Hardening
See Security Configuration for detailed security best practices.Troubleshooting
High Memory Usage
Slow Queries
Sync Failures
Next Steps
Security
Harden your production deployment
Configuration
Fine-tune environment variables
Docker Guide
Docker deployment details