Hosting each bot on a separate server wastes money. A single VPS can run dozens of bots efficiently with proper management.
Architecture
VPS (4 cores, 8GB RAM)
├── Bot 1 (Music Bot) - Node.js
├── Bot 2 (Moderation Bot) - Python
├── Bot 3 (Economy Bot) - Node.js
├── MariaDB (shared database)
└── Nginx (dashboard reverse proxy)
Process Management with PM2
PM2 manages all your bots, regardless of language:
# Node.js bots
pm2 start bots/music-bot/index.js --name "music-bot"
pm2 start bots/economy-bot/index.js --name "economy-bot"
# Python bots
pm2 start bots/mod-bot/bot.py --name "mod-bot" --interpreter python3
# View all bots
pm2 status
# Restart a specific bot
pm2 restart music-bot
# View logs
pm2 logs mod-bot
PM2 Ecosystem File
Create ecosystem.config.js for declarative management:
module.exports = {
apps: [
{
name: 'music-bot',
script: 'bots/music-bot/index.js',
max_memory_restart: '300M',
env: { NODE_ENV: 'production', BOT_TOKEN: 'token1' }
},
{
name: 'economy-bot',
script: 'bots/economy-bot/index.js',
max_memory_restart: '200M',
env: { NODE_ENV: 'production', BOT_TOKEN: 'token2' }
},
{
name: 'mod-bot',
script: 'bots/mod-bot/bot.py',
interpreter: 'python3',
max_memory_restart: '200M',
env: { BOT_TOKEN: 'token3' }
}
]
};
Start all: pm2 start ecosystem.config.js
Resource Allocation
Memory Budget
Plan your RAM:
- OS overhead: 500MB-1GB
- MariaDB: 500MB-1GB
- Bot 1: 200-400MB
- Bot 2: 200-400MB
- Bot 3: 200-400MB
- Buffer: 1-2GB
Total: 4-8GB covers 3-5 bots comfortably.
CPU
Most Discord bots are idle 95% of the time. They spike briefly when processing commands, then idle again. 3-5 bots on a 4-core VPS rarely compete for CPU.
A Space-Node VPS with 4 cores and 8GB RAM runs 5+ Discord bots without performance issues.
Shared Database
Single MariaDB Instance
CREATE DATABASE music_bot;
CREATE DATABASE economy_bot;
CREATE DATABASE mod_bot;
CREATE USER 'music'@'localhost' IDENTIFIED BY 'pass1';
CREATE USER 'economy'@'localhost' IDENTIFIED BY 'pass2';
CREATE USER 'mod'@'localhost' IDENTIFIED BY 'pass3';
GRANT ALL ON music_bot.* TO 'music'@'localhost';
GRANT ALL ON economy_bot.* TO 'economy'@'localhost';
GRANT ALL ON mod_bot.* TO 'mod'@'localhost';
Each bot has its own database and credentials. No cross-bot data access.
Monitoring
PM2 Dashboard
pm2 monit # Terminal-based monitoring
pm2 plus # Web-based monitoring (PM2's paid service)
Custom Health Check
#!/bin/bash
# health_check.sh
for bot in music-bot economy-bot mod-bot; do
status=$(pm2 jlist | python3 -c "import sys,json; bots=json.load(sys.stdin); [print(b['pm2_env']['status']) for b in bots if b['name']=='$bot']")
if [ "$status" != "online" ]; then
echo "ALERT: $bot is $status"
pm2 restart $bot
fi
done
Run via cron every 5 minutes:
*/5 * * * * /scripts/health_check.sh >> /var/log/bot_health.log 2>&1
Directory Structure
/home/bots/
├── music-bot/
│ ├── index.js
│ ├── package.json
│ └── .env
├── economy-bot/
│ ├── index.js
│ ├── package.json
│ └── .env
├── mod-bot/
│ ├── bot.py
│ ├── requirements.txt
│ └── .env
└── ecosystem.config.js
When to Separate
Move a bot to its own server when:
- It consistently uses more than 1GB RAM
- CPU spikes from one bot affect others
- The bot serves 5,000+ servers
- You need to scale independently
For most community bots, a single VPS handles everything efficiently and costs a fraction of separate hosting for each bot.
