VPS vs serverless for bots: cost and limits
VPS vs serverless comes down to one question: does your bot need a process that runs all the time? If it answers occasional messages through a webhook and finishes in seconds, serverless (Vercel, Cloudflare Workers, AWS Lambda) is cheap or free. If your code calls start_polling, keeps a gateway connection to Discord, sends scheduled broadcasts, writes to SQLite or waits a minute on an AI model, a VPS is simpler: $4.49/mo flat, no per-call time limit, no bill per message.
Here's the contrast: serverless plans cap CPU time or run time per call, and the long-polling bot from almost every tutorial runs on none of them. Below: what those limits mean for bots, a "which one for which bot" table, and a migration plan.
What's the difference between a VPS and serverless?
A VPS is a virtual server with dedicated resources: CPU, RAM, disk and an IP address. You install Python or Node.js, run the bot as a service, and it keeps going as long as the server is up. You pay for time, not for messages.
Serverless means you upload a function and the platform runs it for each event: an HTTP request, a queue message, a schedule. Nothing runs between events. You pay per invocation and execution time and never touch a server.
For bots, the deciding factor is how the bot receives updates.
Webhook vs long polling decides it
The Telegram Bot API docs describe two mutually exclusive ways to get updates: getUpdates (long polling) and webhooks (setWebhook). While a webhook is set, getUpdates won't work.
| Long polling | Webhook | |
|---|---|---|
| How it works | the bot keeps asking api.telegram.org for updates | Telegram POSTs each update to your HTTPS URL |
| Needs an always-on process | yes | no |
| Needs a domain and TLS | no | yes, a public HTTPS address |
| Works in a serverless function | no | yes |
| Works on a VPS | yes | only with a public address (0x.cloud servers have none) |
| Sender verification | not needed | X-Telegram-Bot-Api-Secret-Token header when you set secret_token |
Most aiogram, python-telegram-bot, Telegraf and discord.py tutorials start with a persistent connection: polling for Telegram, a gateway WebSocket for Discord. Those bots can't run in a function as written; you'd have to rewrite them around webhooks or Discord's interactions endpoint.
The Telegram docs also note that if your endpoint returns an error, Telegram retries a reasonable number of times and then gives up. So a function has to reply fast and push slow work to a queue.
Serverless Telegram bot in Python: what changes
A serverless version drops start_polling. The function accepts a POST with the update JSON, checks the X-Telegram-Bot-Api-Secret-Token header, hands the update to your dispatcher (feed_update in aiogram, process_update in python-telegram-bot) and returns 200 right away. You register the function URL once with setWebhook and a secret_token. Conversation state, counters and FSM data can't live in memory; they go in an external database or KV store.
Serverless platform limits for bots
Each platform publishes its own free allowance, time limit per call and memory cap, and they change often: check the current numbers in the docs of Vercel, Cloudflare Workers and AWS Lambda.
What that means in practice:
- Vercel Hobby has no overage billing: exceed a limit and the feature stops working for a while. Time spent waiting on an AI model or database doesn't count as active CPU. For always-on work Vercel offers Daemons, but they're in beta with their own monthly quotas, and Vercel itself recommends Pro for workers that run all month.
- Cloudflare Workers Free gives a very small CPU budget per call: enough to accept a webhook and forward it, not enough for heavy processing. The paid plan has a monthly minimum per account.
- AWS Lambda is generous on time, but a bot also needs a Function URL or API Gateway, an IAM role and CloudWatch logs. That's a lot of setup for one bot.
There's also a middle ground: a PaaS that runs a normal long-lived process for you. A free Render web service spins down after a period with no inbound traffic and takes time to wake, and background workers can't use the free instance type. Railway's plans include a small monthly usage allowance and then bill RAM and vCPU by use. Detailed comparisons: Railway alternatives and Render alternatives.
Where serverless gets awkward for bots
- No persistent disk. SQLite, user files and image caches vanish between calls. You add an external database: one more service, one more bill.
- Cold starts. A function that hasn't run for a while answers the first message slower.
- Scheduled work. Reminders, daily digests and generation queues each need a separate platform feature. On a VPS it's one more process or a systemd timer.
- Slow AI calls. Image generation or a long completion can take a minute. That doesn't fit Cloudflare's free CPU budget or other short limits without a queue.
- Unpredictable bills. A broadcast to 50,000 users won't fit in one invocation and needs a queue, and junk traffic hitting your webhook is billed like real calls. A VPS costs the same regardless of message count.
- Debugging. On a server you see the process, logs and disk. Free serverless plans keep runtime logs only briefly.
Where serverless beats a VPS
- Almost no traffic. Ten messages a day on a free tier costs $0.
- Sudden spikes. The platform scales the function when your bot lands in a huge group.
- Zero ops. No OS updates or disk alerts.
- The bot is part of a web app. If your site already lives on Vercel, a webhook route in
/apiis convenient. That's the honest answer to "Vercel vs VPS" for a webhook bot.
VPS vs serverless: which to pick for each bot
| Bot workload | Serverless | VPS |
|---|---|---|
| Replies to commands, few users | fits, often free | fits, from $4.49/mo |
| Long polling or a Discord gateway bot | doesn't work in a function | works as is |
| Stores data in SQLite or files | needs an external DB | DB on the server's disk |
| Scheduled broadcasts and reminders | platform cron plus a queue | systemd timer or in-code scheduler |
| AI generation that takes a minute or more | hits limits, needs a queue | no time limit |
| Several bots plus a database | several functions and services | one server |
| Thousands of requests per second in bursts | scales automatically | needs headroom |
Bottom line: serverless wins at the extremes (near-zero or very spiky load); a VPS wins everywhere in between, especially once the bot has state and background work.
What a bot costs on a VPS
0x.cloud runs KVM servers in Warsaw with NVMe disks and unmetered traffic at up to 1 Gbps:
| Plan | Specs | Monthly | Hourly | Fits |
|---|---|---|---|---|
| s1-1 | 1 vCPU, 1 GB RAM, 15 GB NVMe | $4.49 | ~$0.030750 | one aiogram or Telegraf bot |
| s1-2 | 1 vCPU, 2 GB RAM, 30 GB NVMe | $7.99 | ~$0.054725 | an AI bot with a database, several bots |
| s2-4 | 2 vCPU, 4 GB RAM, 60 GB NVMe | $15.99 | ~$0.109520 | several bots, queues, a database |
One aiogram bot fits on s1-1: a Python process with its library uses tens of megabytes, which leaves room for SQLite and logs. If the bot keeps chat history, talks to PostgreSQL, or you run several bots, take s1-2 with 2 GB.
The price is fixed for the paid period and doesn't depend on message volume. Want to test first? Hourly billing from your balance (your first paid server needs one top-up of at least $5) costs about $0.74 a day on s1-1 and never adds up to more than the monthly price. Setup is $0, and if you delete the server, charges stop right away and the unused amount goes back to your balance. The Bots image ships Python with Telegram and Discord libraries, Node.js with pm2, and a service that keeps your bot running. See every plan on the pricing page.
Moving a bot from serverless to a VPS
- Create a server: s1-1 or s1-2 with Ubuntu 24.04 or the Bots image.
- Decide on webhook vs polling. The simplest path is switching back to long polling. Delete the webhook first or
getUpdateswon't work:
# removes the webhook so the bot can receive updates through getUpdates
curl "https://api.telegram.org/bot<TOKEN>/deleteWebhook"
- Run the bot as a service. Code in a folder, dependencies in a virtualenv, a systemd unit with
Restart=alwaysso it comes back after crashes and reboots. Step by step: deploy a Python Telegram bot. - Move your data. Keep the external database or run PostgreSQL next to the bot.
- Staying on webhooks? That needs a public address with a domain and TLS, which 0x.cloud servers don't have, so on 0x.cloud switch the bot to long polling.
You can hand steps 1–3 to your AI agent in one sentence: it creates the server through the 0x.cloud MCP server or API and shows you the price first.
Create an s1-1 server with Ubuntu 24.04 on 0x.cloud for my aiogram Telegram bot. Show me the dry_run price and wait for my OK before creating it. Then call deleteWebhook for the bot, deploy the code from my repository into a virtualenv and run it as a systemd service with Restart=always.
More on picking a server for bots: Telegram bot hosting.
FAQ
Can I host a Telegram bot on Vercel? Yes, if the bot uses a webhook: Telegram sends each update as an HTTPS request, and the function replies and exits within the plan's time limit. Long polling doesn't work in a function. Vercel Daemons can run always-on processes, but they're in beta and have their own monthly quotas.
Is serverless cheaper than a VPS for a bot? For a small bot with occasional messages, serverless often fits in free tiers. Once the bot needs scheduled jobs, a local database, broadcasts or long AI calls, a VPS is usually simpler and more predictable, starting at $4.49/mo ($0.030750/hour on hourly billing) for 1 vCPU and 1 GB RAM.
Should my bot use a webhook or long polling? Long polling is easier to start and needs no domain or TLS, but it requires an always-on process, so a server. Webhooks need an HTTPS address Telegram can reach from the internet: a function URL or a server with a public address (0x.cloud servers have none, so use long polling there). Telegram doesn't allow both at once.
Why does my serverless bot forget data? Functions have no persistent local disk, so files, SQLite databases and in-memory variables can disappear between invocations. Keep state in an external database or KV store. On a VPS the database can live on the server's NVMe disk.