Black Friday: −50% on everything until November 30

← Back

Telegram Mini App Backend: What to Plan Before Launch So It Doesn't Fall Apart

Published on:

Telegram Mini App Backend: What to Plan Before Launch So It Doesn't Fall Apart

When people order a Telegram Mini App, they almost always talk about screens and buttons. But a month after launch, the problems come not from the interface but from what is under it: the bot replies late, the database slows down, data drifts apart. In this article I go through what I build under a Mini App up front, using my own case.

Which project this is

This is the bot and backend for a crypto Mini App: a crypto mining mini app that needed more than an interface in Telegram. It needed a reliable bot and server pair that could grow with the product. I built the bot commands, the backend server, the SQL database architecture and the database performance optimization.

I give no numbers from this case: the case text has none, and I will not invent results. The approach itself carries over to any Mini App where users have a balance, an action history or progress.

What a Mini App is made of

From outside it is one app. Inside there are usually three layers:

  • Telegram bot: the entry point, commands, notifications, bringing the user back to the app.
  • Backend server: business logic, user checks, calculations, exchange with outside services.
  • Database: everything you cannot lose: users, accruals, actions, settings.

If one layer is rushed, the others feel it. That is why I design them together, not one after another.

What to decide before development starts

1. What is the source of truth

A common source of bugs is logic spread between the bot, the client and the server. I try to make every important value (balance, progress, statuses) be calculated and stored on the server, with the interface only showing it. Then what the user sees and what is recorded cannot diverge.

2. How the database is built

It is better to think through the SQL schema before the first line of code. The questions I ask myself:

  • which entities the product has and how they relate;
  • which queries will be the most frequent;
  • which data will only grow (action history, events);
  • what will need to be counted and shown in an admin panel.

Tables and indexes depend on those answers. Redoing a schema when live users are already in the database is expensive and risky.

3. Where the bottleneck will be

I do not optimize database performance “when it starts to slow down”. I look at the heaviest and most frequent queries early. In mini apps with active users the load often comes in bursts, and the database has to survive them.

4. Which commands the bot needs

In a Mini App the bot does not duplicate the app. Its job is to launch, remind, notify and give quick access to the main thing. Extra commands only confuse, so I keep a short set and clear replies.

Common mistakes

  • Building the interface first and the server part “later”.
  • Keeping important data only on the client side.
  • Not thinking about growth: the schema fits a hundred users, but the product is meant for thousands.
  • Skipping an admin panel: later nobody understands what is going on in the project.

Questions I ask before starting

  • What is the most valuable thing in the app for the user, and what must not be lost?
  • Is there data that is accrued, calculated or changed by rules?
  • Where will the first users come from and what growth do you expect?
  • What do you need to see as the owner: statistics, actions, a list of users?

If you have a similar task, see Telegram Mini App development and the case itself.

Want to discuss your project

Write to me in the bot: https://t.me/chornuy7_tech_bot?start=src_blog. Describe what the app should do, and I will reply in chat with where to start and what to plan early.