Development vs Production: Resource Requirements
Date: 2025-11-08 Context: Ahaia Music web app setup
Key Lesson
Development and production modes in Node.js/Next.js have drastically different resource requirements.
Development Mode (npm run dev)
Memory Usage: ~250 MB for Next.js
- Hot Module Replacement (HMR) - watches files and auto-reloads
- Source maps - for debugging
- Dev server overhead
- Unminified code
- Development dependencies loaded
Process Tree:
npm → shell → node (next CLI) → next-server
Use Case: Local development, coding, testing changes
Not suitable for: Production hosting or resource-constrained environments
Production Mode (npm run build → npm start)
Memory Usage: ~50-100 MB for Next.js
- Optimized, minified bundles
- No file watching
- No source maps
- Production-only dependencies
- Efficient runtime
Build Step:
npm run build- compile and optimize (resource-intensive, done once)- Can be done on different machine or with temporary swap
- Outputs static
.nextdirectory
Runtime:
npm start- serves pre-built files (lightweight)- This is what runs on production server
Server Specs Context
Current Server:
- RAM: 909 MB
- CPU: 2 cores
- Disk: 19 GB (9.1 GB free)
- No swap
Development Mode:
- ❌ Tight - only 116 MB available, dev needs ~250 MB
- Risk of OOM (out-of-memory) kills
Production Mode:
- ✅ Adequate for 1-5 users (~50-100 MB usage)
- ✅ Supports Phase 1 (5-20 concurrent users per architecture docs)
Deployment Strategy
Option 1: Build Elsewhere
# On dev machine (laptop/CI/CD)
npm install
npm run build
# Copy .next/, public/, package.json to server
rsync -av .next/ server:/path/to/app/.next/
rsync -av public/ server:/path/to/app/public/
# On server
npm install --production # Only prod dependencies
npm start
Option 2: Add Temporary Swap
# On server (before build)
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
# Build
npm run build
# Remove swap (optional)
sudo swapoff /swapfile
sudo rm /swapfile
Option 3: Stop Services During Build
# Free up memory
sudo systemctl stop <other-services>
# Build
npm run build
# Restart services
sudo systemctl start <other-services>
# Run production
npm start
Recommendations
- For Active Development: Use a separate dev machine or add swap
- For Production Hosting: Current server specs are fine
- Build Process: Do builds off-server or with temporary resources
- Runtime: Production mode is lightweight enough for this server
Memory Breakdown Example
Development (npm run dev):
next dev processes: 250 MB
Other services: 500 MB
System: 150 MB
Available: ~10 MB ⚠️ Too tight!
Production (npm start):
next start process: 80 MB
Other services: 500 MB
System: 150 MB
Available: 180 MB ✅ Comfortable
Related Links
Takeaway: Don't judge production requirements by development memory usage. They're completely different workloads.