NEWUse coupon code SMX20 to get 20% OFF your first billing cycle on any game server or VPS!Explore Store

TUTORIALS & GUIDES

How to Host a Telegram Bot 24/7 on a VPS: Production Deployment Guide

Master 24/7 telegram bot hosting on a Linux VPS. Learn polling vs webhooks, systemd and PM2 auto-restart daemon setup, SSL configuration, and scaling tips.

Running a commercial Telegram bot from your personal computer or a free hosting tier is a recipe for business failure. Laptops go to sleep, residential internet connections change IP addresses unexpectedly, power cuts drop active client sessions, and free cloud providers abruptly suspend your processes when memory limits spike. For customer service desks, automated order-taking systems, and paid signal communities, intermittent bot outages directly erode user trust and revenue. Reliable telegram bot hosting requires an unmanaged Linux VPS with guaranteed CPU allocations, continuous background process supervisors (like systemd or PM2), and clean network uplinks. This guide provides an end-to-end production deployment blueprint for both Python and Node.js bots.

Polling vs Webhook: Which Architecture Should You Choose?

Before writing a single deployment script, you must determine whether your bot will retrieve incoming user messages using Long Polling (getUpdates) or Webhooks (setWebhook). Each pattern involves fundamentally different server networking and resource consumption profiles:

● Long Polling

Your bot script opens a persistent outbound HTTPS connection to Telegram's API server, waiting for updates. When a user sends a command, Telegram delivers it over the open pipe.

  • Pros: Zero firewall or domain setup required. Runs behind NAT or private IPs effortlessly. Ideal for development and bots with low-to-medium traffic (< 20 requests/sec).
  • Cons: Constant outbound HTTP polling consumes continuous CPU cycles and socket descriptors. Cannot distribute load across multiple servers easily.

● Webhooks (Production Standard)

You register an HTTPS endpoint with Telegram. The instant an event occurs, Telegram makes an inbound HTTP POST request to your public server with the payload.

  • Pros: Near-zero idle CPU and RAM consumption. Instantaneous message delivery. Highly scalable via Nginx load balancers.
  • Cons: Requires a static public IPv4, valid domain name, and trusted SSL certificate (TLS 1.2+).

The Verdict: If your bot manages high-volume customer orders, payment notifications, or group chats with over 5,000 members, always configure a Webhook behind an Nginx reverse proxy. For private automation tools and internal notification scripts, Long Polling managed by systemd is perfectly reliable.

24/7 Production Telegram Bot Hosting Architecture

[Telegram Users / Groups / Channels] │ ▼ [Telegram Cloud API: api.telegram.org] │ HTTPS Webhook Push (Port 443) │ ▼ ┌────────────────────────────────────────────────────────┐ │ ServoMix VPS (Mumbai / Noida DC) │ │ │ │ Nginx Reverse Proxy (SSL Let's Encrypt TLS 1.3) │ │ │ │ │ Internal Proxy (127.0.0.1:8080) │ │ ▼ │ │ ┌────────────────────────────────────────────────┐ │ │ │ Process Supervisor: systemd / PM2 Daemon │ │ │ │ │ │ │ │ ▶ Worker Process: Python (aiogram / pyrogram)│ │ │ │ or Node.js (telegraf / grammy) │ │ │ │ ▶ Healthcheck & Auto-Restart On Crash │ │ │ └───────────────────────┬────────────────────────┘ │ │ │ │ │ ┌───────────────────────▼────────────────────────┐ │ │ │ Local State Storage: SQLite / Redis / Postgres │ │ │ └────────────────────────────────────────────────┘ │ └────────────────────────────────────────────────────────┘

Server Preparation (Ubuntu 24.04, Python / Node, venv)

Provision an Ubuntu 24.04 LTS instance on ServoMix. Avoid using the root user for executing user-facing scripts. Creating an isolated system user prevents accidental operating system file corruption or security breaches:

# Update repositories and basic tools
sudo apt update && sudo apt upgrade -y
sudo apt install -y git curl ufw build-essential python3-pip python3-venv

# Create a dedicated system user for the bot
sudo adduser --disabled-password --gecos "" botuser
sudo usermod -aG sudo botuser

Setting Up Node.js Environment (For JavaScript/TypeScript Bots)

curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt install -y nodejs
sudo npm install -g pm2

Setting Up Python Environment (For aiogram / python-telegram-bot)

su - botuser
mkdir -p ~/telegram-bot && cd ~/telegram-bot
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install aiogram aiohttp python-dotenv

Deploying Bot Code with Git & Environment Variable Security

Never hardcode your Telegram Bot API token directly into your codebase. If your repository is accidentally exposed or pushed to a public branch, scraping bots will compromise your token within 60 seconds and spam your users.

Clone your repository via SSH deploy keys or HTTPS, and generate an isolated .env file on the server:

# Inside /home/botuser/telegram-bot/.env
BOT_TOKEN=7123456789:AAFlkjw098dfSDFKjlw3_sampleTokenHere
ADMIN_TELEGRAM_ID=987654321
ENVIRONMENT=production
DATABASE_URL=sqlite:///bot_database.db

Lock down file permissions so other local users or compromised web services cannot read your bot token:

chmod 600 /home/botuser/telegram-bot/.env

Keep It Alive with systemd or PM2 (Zero Downtime)

If you run your bot inside a terminal window using python bot.py, closing your SSH session kills the bot. Even if you use nohup or screen, any unexpected API timeout or memory exception will crash the process indefinitely. You need a dedicated daemon supervisor.

Option A: Managing Python Bots with Linux systemd

Create a systemd unit file at /etc/systemd/system/telegram-bot.service:

[Unit]
Description=Telegram Business Bot Daemon
After=network.target

[Service]
Type=simple
User=botuser
WorkingDirectory=/home/botuser/telegram-bot
ExecStart=/home/botuser/telegram-bot/venv/bin/python main.py
Restart=always
RestartSec=5s
EnvironmentFile=/home/botuser/telegram-bot/.env

# Security Hardening Directives
ProtectSystem=full
NoNewPrivileges=true

[Install]
WantedBy=multi-user.target

Reload systemd, enable the service to start automatically on system boot, and start it:

sudo systemctl daemon-reload
sudo systemctl enable telegram-bot
sudo systemctl start telegram-bot
sudo systemctl status telegram-bot

Option B: Managing Node.js Bots with PM2

cd /home/botuser/telegram-bot
pm2 start index.js --name "tg-order-bot" --max-memory-restart 300M
pm2 save
pm2 startup systemd

Set Up Webhook with Nginx & Let's Encrypt SSL

Telegram strictly enforces that all webhook URLs use valid SSL/TLS certificates issued by a trusted CA. Self-signed certificates require complex manual public key uploads, whereas a free Let's Encrypt certificate takes 60 seconds to configure.

Assuming your internal bot runs a local HTTP webhook server on port 8080 (e.g. via aiohttp or express), create an Nginx configuration file at /etc/nginx/sites-available/telegram-webhook:

server {
    server_name bot.yourdomain.in;

    location /webhook {
        proxy_pass http://127.0.0.1:8080;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
sudo certbot --nginx -d bot.yourdomain.in --agree-tos -m admin@yourdomain.in

Register your webhook URL directly with Telegram's servers via curl:

curl -F "url=https://bot.yourdomain.in/webhook" "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook"

Logs, Monitoring & Auto-Restart Troubleshooting

In a production environment, you should never have to guess why a bot rejected an input. Systemd forwards all stdout and stderr streams directly to the Linux journal system. You can inspect real-time live logs with:

# Stream real-time logs:
sudo journalctl -u telegram-bot -f

# Check last 100 log lines on failure:
sudo journalctl -u telegram-bot -n 100 --no-pager

If you are using PM2, execute pm2 logs tg-order-bot or pm2 monit for a visual terminal dashboard showing real-time CPU spikes, heap memory usage, and exception stack traces.

Scaling Architecture for 10,000+ Active Users

When your bot surpasses 10,000 active users or handles broadcast notifications, executing heavy business logic (such as generating PDF invoices or querying external CRM APIs) directly inside the message-receiving handler will block Telegram's incoming requests and trigger timeout drops.

  • Asynchronous Message Handlers: Always leverage asynchronous frameworks such as aiogram 3.x (Python) or GrammY / Telegraf (Node.js). Never use blocking I/O functions like requests.get() or time.sleep().
  • Background Task Queues: Offload heavy execution tasks to a local Redis instance paired with Celery or BullMQ. The bot acknowledges Telegram instantly with an HTTP 200 OK, while background workers process the job.
  • Database Connection Pooling: SQLite fails under high concurrent writes. Upgrade to a local PostgreSQL instance running with connection pooling to handle simultaneous customer checkout flows.
Recommended Plan for Telegram Bots

Starter KVM Cloud VPS (India)

Specs: 2 vCore • 8 GB DDR4 ECC RAM • 40 GB NVMe Storage • Dedicated Indian IPv4 • 1 Gbps Port • 2+ Tbps Anti-DDoS Protection.

Plans start at just ₹270/month • Instant automated OS setup.

Choose a Bot VPS Plan →

Frequently Asked Questions

Can I host a Telegram bot for free without a VPS?

Free hosting platforms like Heroku, Render, or free Replit tiers put bots to sleep after 15 minutes of inactivity and enforce severe monthly execution limits. For commercial bots requiring 99.9% uptime and zero latency, an entry-level KVM VPS is mandatory.

Should I use Long Polling or Webhooks for my Telegram bot?

Long Polling is simpler for development because it requires no public domain. However, Webhooks are far more efficient for production because Telegram pushes events instantly via HTTPS, conserving server CPU and eliminating latency.

How does systemd or PM2 keep my bot online after a crash?

Both systemd and PM2 function as process supervisors. If your bot crashes due to an unhandled API timeout or memory exception, the supervisor automatically restarts the process within seconds. They also ensure your bot boots immediately after a VPS reboot.

How many Telegram bots can I run on a single 2GB or 4GB VPS?

A standard Python or Node.js Telegram bot consumes approximately 60MB to 120MB of RAM. On a 2GB RAM VPS, you can comfortably run 10 to 15 lightweight bots simultaneously using PM2 or Docker.

Deploy This on ServoMix in Minutes

Get pure NVMe storage, dedicated Indian IP addresses, and 99.95% uptime for your Telegram bots. Instant automated setup with full root access.

Launch Your Bot VPS →
2026 Cloud Architecture

Enterprise Developer Infrastructure: Key Differentiators

When deploying modern web runtimes (Node.js, Next.js SSR, Python FastAPI, n8n automations, or Docker container clusters), traditional oversold shared hosting or high-latency overseas cloud providers introduce severe CPU steal time, IOPS bottlenecks, and unpredictable monthly bill shocks. ServoMix delivers true kernel-level KVM virtualization backed by AMD EPYC™ 7C13 and AMD EPYC 7C13 compute nodes in Tier-3 Mumbai & Noida datacenters.

Sub-10ms

Domestic Peering

Direct NIXI & DE-CIX Mumbai interconnects provide sub-10ms response times across Jio, Airtel, and Vi broadband backbones.

7,000 MB/s

PCIe Gen4 NVMe

Enterprise Gen4 NVMe arrays deliver up to 850,000 IOPS, accelerating npm builds, Docker pulls, and database writes.

2+ Tbps

Inline DDoS Shield

Continuous L3/L4/L7 automated packet scrubbing filters volumetric floods without dropping legitimate API requests.

Feature-by-Feature Comparison: ServoMix vs Traditional Providers

Feature ServoMix Developer VPS Legacy Indian & Hyperscaler Hosts
Compute Silicon AMD EPYC™ 7C13 / AMD EPYC 7C13 (3.70 GHz) Older Xeon E5-2680 v4 / Shared vCPU Slices
Virtualization Type 100% Dedicated KVM (Zero Overselling) OpenVZ / Oversold Containers with CPU Steal
Storage Speed Pure Enterprise Gen4 NVMe (7,000 MB/s) Standard SATA SSD (500 MB/s) or Spun Disks
Bandwidth & Ports 1 Gbps Dedicated Unmetered Port 100 Mbps Shared or Expensive Per-GB Egress
Billing & Currencies ₹270/mo Flat (Instant UPI, Zero Forex) USD Billed with 3.5% Forex Markups + 18% Tax

Ready to Deploy High-Performance Indian Cloud VPS?

Instant automated activation in under 60 seconds with instant UPI / Net Banking.

Frequently Asked Questions

Can I host a Telegram bot for free without a VPS?

Free hosting platforms like Heroku, Render, or free Replit tiers put bots to sleep after 15 minutes of inactivity and enforce severe monthly execution limits. For commercial bots requiring 99.9% uptime and zero latency, an entry-level KVM VPS (starting at ₹270/mo) is mandatory.

Should I use Long Polling or Webhooks for my Telegram bot?

Long Polling is easier to test during development because it doesn't require a public domain or SSL certificate. However, Webhooks are far more efficient for production because Telegram pushes updates instantly via HTTPS, conserving server CPU cycles and eliminating polling delays.

How does systemd or PM2 keep my bot online after a crash or server reboot?

Both systemd and PM2 function as process supervisors. If your bot crashes due to an unhandled API timeout or memory exception, the supervisor automatically restarts the process within seconds. They also ensure your bot boots immediately when the VPS reboots.

How many Telegram bots can I run on a single 2GB or 4GB RAM VPS?

A standard Python (aiogram / python-telegram-bot) or Node.js (telegraf) bot consumes approximately 60MB to 120MB of RAM. On a 2GB RAM VPS, you can comfortably run 10 to 15 lightweight bots simultaneously using PM2 or Docker.

Was this article helpful?

Your feedback helps us continuously improve ServoMix guides.

Share this article

Know someone who may find this guide useful?

How to Host a Telegram Bot 24/7 on a VPS: Production Guide ( | ServoMix