DEV Community

Keeping a Telegram bot online 24/7: polling vs webhooks, the 409 error, and where to host it

Your bot works on your laptop, then dies the moment you close the terminal. Here is what a bot needs in production, the three mistakes that take most bots down, and the hosting options with each provider's own prices.

Polling or webhook: pick one

Telegram delivers updates in one of two ways, and a bot uses one or the other, never both:

  • Polling (getUpdates): the bot asks Telegram for new messages in a loop. The process must never stop, so any host that puts idle processes to sleep stops your bot.
  • Webhook: Telegram sends each update to your HTTPS address, on port 443, 80, 88 or 8443. You need a public address with a certificate, but your code only has to answer requests.

Rule of thumb: polling for a small bot on an always-on host; a webhook when you already run a web server.

A minimal bot that survives production (aiogram 3)

import asyncio, logging, os
from aiogram import Bot, Dispatcher
from aiogram.filters import CommandStart
from aiogram.types import Message

dp = Dispatcher()

@dp.message(CommandStart())
async def start(message: Message):
    await message.answer("Hi! I'm alive.")

async def main():
    logging.basicConfig(level=logging.INFO)
    bot = Bot(os.environ["BOT_TOKEN"]) # the token lives in the environment, not in git
    await bot.delete_webhook(drop_pending_updates=True) # polling and a webhook can't coexist
    await dp.start_polling(bot)

if __name__ == "__main__":
    asyncio.run(main())

Three things matter more than the framework: the token comes from an environment variable, any old webhook is removed before polling, and exactly one copy runs.

The three errors that take bots down

Conflict: terminated by other getUpdates request (409). Two processes are polling with the same token: usually an old deploy that is still running, or your laptop and the server at once. Stop one. If a webhook is set, call deleteWebhook first.

429 Too Many Requests. Flood control. Telegram asks bots to stay around one message a second per chat, 20 a minute per group, and about 30 a second in a broadcast. Wait the retry_after seconds the error gives you, then send the same request again; send broadcasts from one queue at a steady pace.

The bot silently stops after a few hours. Either the host put it to sleep (most free tiers do), or it crashed and nothing started it again. On a VPS, let systemd restart it:

[Unit]
Description=My Telegram bot
After=network-online.target

[Service]
WorkingDirectory=/opt/mybot
EnvironmentFile=/opt/mybot/.env
ExecStart=/opt/mybot/.venv/bin/python bot.py
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

Where to host it

Prices from each provider's own page, read on 19 November 2026; check them again before you buy.

Option Smallest always-on process What you still maintain
A VPS Varies by provider; the cheapest option per bot if you run several The OS, updates, systemd, deploys, HTTPS for a webhook
Railway Hobby plan: $5/month, including $5 of usage Your code
Render Background worker: $7/month (0.5 CPU, 512 MB) Your code
Fly.io shared-cpu-1x, 256 MB: $2.19/month Your code
Livops 19,000 UZS/month, paid with Payme or Click Your code

Free options: a free tier that sleeps will not run a polling bot. A low-traffic webhook bot can run on serverless functions, because it only has to answer requests.

Disclosure I work on Livops, a deploy platform built in Tashkent. A bot is its own service type there: always running, no public port needed, started again if it crashes, and you get a Telegram message if it keeps falling over. It fits developers in Central Asia best: the servers are in Uzbekistan and billing is in so'm (international cards are not live yet).

The full comparison, with a source for every price, is here: https://livops.dev/en/hosting/telegram-bot

More on the errors above:

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.