Always-on containers vs serverless functions
Always-on containers or serverless functions for an AI-built app? See when each model fits, compare cold starts, connections, state, and cost.
A serverless function runs your code only when a request arrives. An always-on container runs your code all the time. In short, use always-on hosting when your app or bot must keep running, respond immediately, or do background work. Functions fit short, occasional requests.
This article compares models, not products. Platforms differ in their limits, so check a platform's own documentation before you rely on a number.
Who this comparison is for
You have an app, and you need to pick how it runs. For example:
- a Discord bot that stays connected and posts daily stats
- a contact form handler that runs a few times a day
- a dashboard that must load quickly for the first visitor each morning
Start-up delay
A function that has been idle might need to start before it answers, which delays the first request. Platforms call this a cold start. A container is already running, so it answers the first request as quickly as the hundredth.
Long connections and background work
Many serverless platforms limit how long one run can last. That suits a quick request. It doesn't suit a chat bot that holds a connection open, or a loop that checks a data source every minute. A container keeps running for as long as you need it.
Data that must last
In both models, keep anything that must last in a database or in file storage. A function keeps nothing in memory that you can rely on. An always-on app can keep recent data in memory, but each new deploy starts it fresh.
How the cost behaves
Functions are billed by use, so a quiet app costs little and a busy one costs more. A container is billed by size, so the price stays the same until the app outgrows that size.
When each one fits
Serverless functions fit short work with irregular traffic:
- a webhook receiver or form handler that runs a few times a day
- a task that finishes well inside the platform's time limit
- an app where a slower first request doesn't matter
Always-on containers fit apps that stay busy between requests:
- a chat bot that holds a connection open, or a worker that checks a queue
- an app that must answer the first request without delay
- a budget that needs the same price every month
Most apps that an AI coding agent builds with a database belong in the second group, including bots, data tools, and dashboards. A container also serves short requests, so it covers an app that has a little of both.
How xhostd runs apps
xhostd runs every channel, one running environment of your app, as an always-on container on every plan. Your app never sleeps, so it never has a cold start. The product page describes production and test environments.
- Background workers. A worker runs a loop and serves no web page. Read Run a bot or data tool on xhostd.
- A database for each channel. Each channel that runs code has its own Postgres database. A static site has none.
- A fixed price. A plan sets your CPU, memory, and storage for a fixed monthly price that doesn't depend on users or traffic. Read the pricing page for each plan.
If your code was written as serverless functions, your agent can adapt it to run on xhostd. To compare always-on hosting with a server that you manage yourself, read VPS vs. managed hosting: xhostd compared.