Webhook vs Long Polling for Telegram Bots
· 4 min read · 18+ readers

A Telegram bot must receive updates from Telegram. There are two supported ways: your program asks for them (long polling with
getUpdates) or Telegram pushes them to your server (a webhook set with setWebhook). Both deliver the same update objects. This guide helps you pick one and switch safely.
How long polling works
Your program calls getUpdates with a timeout, for example 30 seconds. Telegram holds the request open until an update arrives or the timeout ends. You process the updates, then call again with offset set to the highest update_id plus one. That confirms the earlier updates so they are not sent again.
const r = await api("getUpdates", { offset, timeout: 30, allowed_updates: ["message", "callback_query"] });
Strengths:
- Works anywhere with outbound internet access, including your laptop.
- No public address, certificate or domain needed.
- Easy to debug.
Weaknesses:
- Needs a process that stays running.
- You must manage reconnects and offsets.
- Only one consumer may poll a bot at a time. A second one causes
409 Conflict.
How a webhook works
You tell Telegram a public HTTPS address with setWebhook. For every update Telegram sends an HTTP POST with the update as JSON. Your server replies with a 2xx status quickly. If it does not, Telegram retries for a while.
curl "https://api.telegram.org/bot$BOT_TOKEN/setWebhook" \
-d url="https://bot.example.com/telegram" \
-d secret_token="a-long-random-string"
Strengths:
- No constant polling. It suits serverless platforms that run only when a request arrives.
- Updates arrive as they happen.
- Easy to scale behind a load balancer.
Weaknesses:
- Needs a public HTTPS endpoint with a valid certificate.
- You must return fast, so slow work needs a queue.
- You must verify requests really come from Telegram. See secret token setup.
- Harder to run on a laptop, though tunnels exist for testing.
Rules to remember
- Webhook and
getUpdatesare mutually exclusive. While a webhook is set,getUpdatesfails. UsedeleteWebhookbefore polling again. - Webhooks allow only certain ports. The documentation lists 443, 80, 88 and 8443.
- HTTPS is required. A self-signed certificate is possible if you upload the public key, but a normal certificate from a public authority is simpler.
getWebhookInfoshows the current URL, pending update count and the last error. Use it first when something fails.drop_pending_updatesonsetWebhookordeleteWebhookdiscards the backlog.
Which should you choose
| Situation | Suggestion |
|---|---|
| Learning, prototypes | Long polling |
| Bot on a small server that stays up | Either; webhook is cleaner |
| Serverless (functions) | Webhook |
| Several instances for load | Webhook |
| No public domain | Long polling |
| Strict firewalls blocking inbound traffic | Long polling |
Migrating safely
From polling to webhook:
- Deploy your HTTPS endpoint and test it with a manual POST.
- Stop the polling process.
- Call
setWebhookwith your URL and secret token. - Call
getWebhookInfoand check there is no error. - Send the bot a message and watch your logs.
From webhook to polling: call deleteWebhook, then start polling.
Handling duplicates
Telegram can retry an update if your server did not answer in time, so make handlers idempotent. Store the last handled update_id and skip repeats, or design operations so that doing them twice is harmless. This matters most for payments and for anything that sends messages.
Performance tips
- Acknowledge first, work later. Return 200 immediately and process in the background.
- Set
allowed_updatesto what you need, to reduce traffic. - Use
max_connectionson webhooks to limit parallel deliveries if your server is small.
Quick checklist
- Decide polling for development and webhook for production.
- Never run both for one token.
- Use allowed_updates to receive only what you handle.
- Reply fast on a webhook and queue slow work.
- Make handlers safe to run twice.
- Check getWebhookInfo after every change.
- Keep only one polling instance.
- Document how to switch back.
A note on ordering
Telegram delivers updates in order for a bot, but parallel webhook workers can process them out of order. If order matters, such as for steps in a conversation, store state in a database and check it, or serialise work per chat. Do not rely on the order in which your workers finish.
Frequently asked questions
Can I run both polling and a webhook?
No. Choose one at a time per bot token.
Does a webhook cost more?
Not by itself. Hosting differs. Serverless webhooks can be very cheap for small bots.
Why do I get 409 Conflict?
Two processes are polling, or a webhook is set while you call getUpdates. See common errors.
Can I test a webhook locally?
Yes, with a tunnelling tool that gives you a public HTTPS URL. Remove the webhook when finished.
Related guides

Set Up a Telegram Webhook with HTTPS and a Secret Token
Register a webhook with setWebhook, protect it with secret_token, check getWebhookInfo, pick allowed_updates and handle retries, with a short Node example.

Telegram Bot API Basics: Methods, Updates and Responses
How the Telegram Bot API works: URL format, JSON responses, update objects, common methods, parse modes, keyboards and how to read errors.

Host a Telegram Bot Cheaply: Options and Trade-offs
Where to run a Telegram bot for little money: your own computer, a small server, serverless functions and container platforms, with reliability and security tips.

A Telegram Webhook on AWS Lambda or a Small Server
Two ways to receive Telegram updates: an AWS Lambda function URL and a tiny Node server behind HTTPS, with secret token checks, fast replies and queues.

Common Telegram Bot Errors and How to Fix Them
A troubleshooting table for Bot API errors: 400, 401, 403, 409, 429 and 5xx, with causes and fixes for polling, webhooks, groups, payments and Mini Apps.

Add a Bot as Channel Admin and Post to Your Channel
Give a bot posting rights in a Telegram channel, find the chat id, send posts with sendMessage, schedule them from code and fix common permission errors.
More in Build on Telegram
- Bot Privacy Mode and Group Admin Rights Explained
- BotFather Commands: What Each One Does
- Connect a Bot to Your Telegram Business Account (Chatbot Mode)
- Connect Your Backend to a Telegram Bot: A Practical Architecture
All topics: Build on Telegram · Guide index · Explore Telegram · About TSocial