Cloud & Virtualization
Serverless Architecture: Real Pros, Real Cons, and When a VPS Fits Better
By NileVPS Team · Published · 5 min read
اقرأ المقال بالعربي"Serverless" is one of the most misunderstood words in hosting. There are still servers; you just do not manage them. You upload a function, connect it to a trigger such as an HTTP request, a queue message or a file upload, and the platform runs it on demand, scales the number of copies up and down, and bills you for invocations and execution time. That model is genuinely useful for some workloads and a poor fit for others. This article walks through how it works, the trade-offs that matter in practice, and a simple way to decide whether your project belongs on functions or on a VPS.
How serverless actually works
A function platform follows this cycle:
- An event arrives (HTTP call, cron schedule, message on a queue, object written to storage).
- The platform finds a warm instance of your function or starts a new one in a lightweight sandbox.
- Your handler runs, returns a result and the instance stays idle for a while in case another event arrives.
- After a period of inactivity the instance is destroyed.
Because instances can be destroyed at any time, functions are stateless by design. Anything that must survive between calls, such as sessions, uploaded files or counters, has to live in an external database, cache or object store.
The advantages
No server administration
You do not patch an operating system, configure a firewall or tune a web server. For a small team that wants to ship a webhook handler or an image resizer, removing that work is the main attraction.
Fine-grained scaling
Each request can get its own instance, so a sudden burst of events is absorbed by running more copies in parallel. When traffic drops to zero, nothing runs.
Pay per use for spiky or tiny workloads
A job that runs a few hundred times a day can cost very little, because you are not paying for a machine that sits idle the rest of the time.
The disadvantages
Cold starts
When no warm instance exists, the platform must create one, load your runtime and run your initialisation code. That adds latency to the first request, especially with large dependencies. Workarounds such as minimum instances usually cost extra.
Execution limits
Platforms impose maximum run times, memory caps, payload size limits and sometimes restrictions on outbound connections. Long video encoding, persistent WebSocket servers or background workers that run for hours are awkward or impossible.
Unpredictable bills at steady load
Per-invocation pricing is cheap when traffic is small and bursty. When traffic is high and constant, the same work is often cheaper on a fixed-price server that runs at a healthy utilisation. Add data transfer, API gateway fees and managed database charges and the total can be hard to forecast.
Database connection pressure
Hundreds of short-lived function instances each opening a connection can exhaust a traditional database such as PostgreSQL or MySQL. You will typically need a connection pooler or a database designed for this pattern.
Lock-in and harder debugging
Triggers, permissions and configuration are platform specific, so moving away means rewriting glue code. Tracing a request across several functions also requires good logging from day one.
Serverless vs VPS at a glance
| Factor | Serverless functions | VPS |
|---|---|---|
| Server management | Handled by the platform | You manage the OS (or use a control panel) |
| Scaling | Automatic, per request | Manual resize or adding servers |
| Cost model | Per invocation and runtime | Fixed monthly price |
| Long-running processes | Limited by timeouts | No limit |
| Persistent connections (WebSockets, bots) | Awkward | Natural fit |
| Latency | Cold starts possible | Process always warm |
| Portability | Platform specific | Standard Linux or Windows |
When each option makes sense
Serverless is a good fit for:
- Webhooks and small API endpoints with irregular traffic.
- Scheduled jobs that run for seconds, not hours.
- Event processing such as resizing an image after upload.
- Prototypes where you want zero infrastructure work.
A VPS is usually the better choice for:
- Websites and APIs with steady traffic, where a fixed price beats per-request billing.
- Telegram bots, trading bots and anything that keeps a connection open.
- Databases, queues, caches and background workers.
- Applications that need specific system packages, custom kernel settings or full root access.
Many teams combine both: the main application runs on a VPS with a predictable cost, while a few bursty side tasks run as functions.
A practical decision checklist
Before choosing, answer these questions:
- Is my traffic mostly flat or mostly spiky with long idle periods?
- Does any request or job run longer than a few minutes?
- Do I need open connections, local disk state or background processes?
- Can my database handle many short-lived connections?
- How much would it cost me to move to another provider later?
If most answers point toward steady traffic, long tasks and state, start with a server. Our guide to server scaling for traffic spikes explains how to handle growth on a VPS without rewriting your app, and you can compare plan sizes on the pricing page.
FAQ
Does serverless mean there are no servers at all?
No. The code still runs on physical servers in a data center. "Serverless" only means the provider manages those machines, the operating system and the scaling, so you deploy functions instead of maintaining hosts.
Is serverless always cheaper than a VPS?
Not always. It is often cheaper for small or very irregular workloads because you pay nothing while idle. For steady, high traffic a fixed-price VPS running at good utilisation is frequently the more economical option, and its cost is easier to predict.
Can I run a Telegram bot or WebSocket server on serverless?
A bot that uses webhooks can work, since each update arrives as an HTTP request. Bots using long polling, and servers that keep WebSocket connections open, fit poorly because functions have time limits and are destroyed when idle. A small VPS is the simpler home for them.