Reading mode:
Key Takeaways (TL;DR)
  • Developers frequently face the challenge of efficiently managing numerous Telegram bots, especially when each user requires a dedicated instance.
  • The proposed architecture centers on a shared webhook for all bots.
  • During the development and testing of such a system, four critical bugs were identified and resolved within the code, underscoring the importance...

Innovative Approach to Scaling Telegram Bots

Developers frequently face the challenge of efficiently managing numerous Telegram bots, especially when each user requires a dedicated instance. PROSTO24 explores a solution that enables hosting hundreds of bots within a single Node.js process by utilizing a shared webhook and a PostgreSQL queue. This method aims to minimize resource consumption while maintaining high performance.

Key Architectural and Performance Considerations

The proposed architecture centers on a shared webhook for all bots. Every user interaction with a bot generates an HTTP request from Telegram. With a substantial user base (up to 300,000 people per month) and multiple interactions per session, all these requests converge on a single POST endpoint. It is critical for this endpoint to be exceptionally fast and resilient, as delays directly impact user experience.

  • Throughput: This is directly determined by the maximum number of connections (max_connections) and the response time. For instance, with 40 connections and a 200 ms response time, 200 updates per second can be processed. Increasing the response time to two seconds dramatically reduces this to 20 updates, leading to significant delays for end-users.
  • PostgreSQL Queue: For processing requests that demand more time, a PostgreSQL-based queue employing the SKIP LOCKED mechanism is utilized. This offloads resource-intensive operations from the webhook, keeping it lightweight and responsive.
  • Mini App Integration: The implementation of a Mini App, merely 5 KB in size, exemplifies the commitment to resource minimization and interaction optimization.
  • Atomic Deduplication: Ensuring atomic deduplication by update_id is mandatory for correct message processing and preventing redundant operations.
  • API Method Return: The webhook can return a Telegram API method call in response to a request, offering additional avenues for interaction optimization.

During the development and testing of such a system, four critical bugs were identified and resolved within the code, underscoring the importance of meticulous analysis and debugging in creating scalable solutions.

Interactive Hardware & AI BenchmarkFull VRAM & ROI Calculator →
Can Your GPU Run 2026 Local AI Models?
✓ Optimal (100% GPU VRAM, ~55-85 tok/s)ollama run qwen3:14b