Skip to content
Deployment
step 1/5

Reading — step 1 of 5

Read

~1 min readProduction

Deployment

How to run a bot 24/7:

VPS (DigitalOcean, Linode, AWS EC2):

  • Standard $5-10/month box.
  • Run process in tmux/screen or systemd.
  • ~99.9% uptime.

PaaS (Heroku, Railway, Fly.io):

  • Push code, they run it.
  • Easy.
  • Free tiers limited.

Serverless (AWS Lambda, Cloudflare Workers):

  • Webhook-triggered.
  • Pay per invocation.
  • Cold start latency.
  • Good for low-traffic bots.

Container (Docker on K8s):

  • Reproducible deployment.
  • Scale horizontally.
  • Heavyweight for single bot.

systemd service example:

[Unit]
Description=My Bot
After=network.target

[Service]
ExecStart=/usr/bin/python /opt/bot/main.py
Restart=always
User=botuser
Environment=BOT_TOKEN=secret

[Install]
WantedBy=multi-user.target

Environment variables:

  • Tokens, API keys, DB URLs.
  • Never commit to git.
  • Use .env in dev; secrets manager in prod.

Logging:

  • stdout to systemd journal / Docker logs.
  • File for persistence.
  • Structured (JSON) for parsing.

Monitoring:

  • Uptime monitor (UptimeRobot, BetterUptime).
  • Heartbeat: bot sends "I'm alive" to monitor every 5 min.
  • Alerts on missed heartbeats.

Auto-restart:

  • systemd Restart=always.
  • pm2 in Node.js.
  • Watchdogs for stuck bots.

Updates:

  • Hot reload (limited).
  • Rolling restart: stop, deploy, start.
  • Brief downtime acceptable for most bots.

Backup:

  • Database snapshots.
  • Token rotation if compromised.

Privacy:

  • Don't log message contents (if avoidable).
  • Honor data deletion requests.
  • GDPR for EU users.

Cost:

  • Small bot: $5/month.
  • Mid: $20-50/month.
  • Large (many servers): $200+/month + DB + Redis.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…