Think about the usual path for a developer who wants to build a small Telegram bot or an interactive Telegram Mini App (TMA). The idea itself is simple—a clicker game, a meetup registration form, or a catalog with a couple dozen items. Yet to get it running in production, you have to march through the full circle of infrastructure hell:
- Rent a virtual private server (VPS) from a hosting provider.
- Set up Linux, install Node.js or Python, and configure Nginx as a reverse proxy.
- Issue an SSL certificate via Let's Encrypt (because Telegram strictly requires HTTPS for webhooks and Mini Apps).
- Spin up and configure a database (PostgreSQL or Redis).
- Wire up systemd or Docker Compose to restart the process when it crashes.
For an indie developer or a team testing a quick hypothesis, all that overhead is often a dealbreaker.
Recognizing this, Pavel Durov's team made an unexpected yet completely logical move: they baked a full-fledged Serverless Execution Environment directly into the platform's infrastructure, managed right through the main service bot, @BotFather.
Let's peek under the hood of this technology, examine the runtime architecture, and look at actual serverless function code.
Architecture: How the V8 Isolates Runtime Works
When most people hear "Serverless," they picture classic AWS Lambda or Google Cloud Functions, where an isolated micro-container spins up for each request. The container approach has one glaring drawback: cold starts that can take anywhere from hundreds of milliseconds to several seconds.
Telegram took a page from modern edge platforms like Cloudflare Workers and Deno Deploy:
- V8 Isolates: the environment doesn't boot an OS or a container. Instead, it creates a lightweight, isolated JavaScript context inside the memory of an already-running Telegram system process.
- Near-zero cold starts: spinning up an isolate takes less than 5 milliseconds. When a user opens a Mini App, the response feels instantaneous.
- Platform-level cryptographic security: one of the most common bugs in Mini Apps is botching the
initDatasignature check on the backend—or leaking the bot token to the frontend. In Telegram Serverless, user authentication is verified by Telegram's own servers before the request ever reaches your function.
Built-in Distributed Database (Cloud KV)
Alongside the execution runtime, you get a built-in Key-Value store.
Infographic diagram of Telegram's distributed Cloud KV database: contextual data isolation by user and chat across a global network of data centers.
The database is distributed across Telegram's global network of data centers, keeping read and write network RTT to a minimum. Its best feature is contextual scoping:
- Records can be scoped to a specific user (
userId). - Records can be isolated to a specific chat or group (
chatId). - Atomic increment operations are supported out of the box (crucial for scores, coin balances, or click counters).
Let's look at a real JavaScript cloud handler that accepts requests from a Telegram Mini App and saves game progress:
// index.js — server handler in Telegram Serverless
export default async function handleRequest(event, context) {
const { user, request, db } = context;
// Security: Telegram has already validated initData,
// so user.id is guaranteed to belong to the caller!
if (!user || !user.id) {
return {
status: 401,
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ error: "Unauthorized request" })
};
}
const url = new URL(request.url);
// Routing: save player score
if (request.method === "POST" && url.pathname === "/api/save-score") {
try {
const payload = await request.json();
const pointsToAdd = Math.max(0, parseInt(payload.points, 10) || 0);
// Atomically read the current score or initialize to zero
const userKey = `user:${user.id}:score`;
const currentScore = (await db.get(userKey)) || 0;
const updatedScore = currentScore + pointsToAdd;
// Save the updated result to Cloud KV
await db.set(userKey, updatedScore);
return {
status: 200,
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
success: true,
userId: user.id,
score: updatedScore
})
};
} catch (err) {
return {
status: 400,
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ error: "Invalid JSON format" })
};
}
}
// Route for reading the leaderboard
if (request.method === "GET" && url.pathname === "/api/my-score") {
const score = (await db.get(`user:${user.id}:score`)) || 0;
return {
status: 200,
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ userId: user.id, score })
};
}
return {
status: 404,
body: "Endpoint not found"
};
}
Notice how concise that is: we didn't have to install express, configure CORS, import a Redis client, or verify an HMAC-SHA256 signature with Node's crypto module. The runtime passes a context object that already includes user, request, and the db interface.
Deploying Code Through BotFather
The deployment workflow is built straight into the chat with the bot:
# 1. Open @BotFather in the Telegram client
# 2. Run /mybots -> select your bot
# 3. Go to "Bot Settings" -> "Cloud Serverless"
# 4. Enable cloud functions and upload your source file or link a GitHub repository
Once uploaded, the platform compiles your JavaScript into V8 bytecode and propagates it across its edge network in seconds. Your bot gets an internal protected webhook, and your Mini App gets a secure public URL like https://<bot_username>.tgcloud.io/api/.
Given how fast automation tools and AI agents in the Telegram ecosystem are evolving, being able to spin up a working backend in a couple of minutes opens the door to tons of quick integrations.
Where Serverless Hits Its Limits
As appealing as it is, there's no free lunch: the serverless runtime enforces strict hardware limits dictated by its multi-tenant nature:
- RAM limit: up to 128 MB per isolate. Trying to load a heavy ML model or process a 4K bitmap will crash immediately with an OOM.
- Execution timeout: max CPU time is capped at 5–10 seconds. Long-running background jobs or heavy analytical PDF generation don't belong here.
- Database constraints: a Key-Value store doesn't support complex SQL joins, full-text search, or transactions across arbitrary data graphs.
If your project is a casual game, a booking service, a quiz, a support bot, or a promo app, Telegram Serverless covers 100% of what you need without spending a dime on infrastructure. But if you need a complex relational schema or heavy compute, a dedicated server is still irreplaceable.

![Node.JS [ru]](/api/digests/it_development/daily/20261022/assets/sources/we-use-js.jpg?v=a0f44cd5adea38f5565ca34efcbf68f295fb7e34338ebf79f7f36277e0148001)