KustBots  /  Case study: Python to Go

Python to Go, in one restart.

On 11 September 2026 we moved our link remover bot, which sits in 81,300 Telegram groups, from Python to Go. The switch took a single Heroku dyno restart: 10–15 seconds offline, with no group losing a setting.

500K+active users
81,300groups protected
9,703apps deployed
50bare-metal machines

The starting point

The link remover was a single long-running Python process serving every group. It worked, but at 81,300 groups we wanted more headroom and more predictable behaviour under load, which is exactly what Go is good at.

The cutover

We rewrote the bot in Go against the same database and the same fields, so every group’s settings carried over without a migration. Then we switched production in one dyno restart. Downtime was 10–15 seconds.

What went wrong on first boot

When the Go version first started, Telegram was holding more than 72,000 old updates for the bot, and the pile was growing by about 300 a second. The new bot dutifully worked through stale messages and answered nothing new, including our own test command.

We began a rollback to Python, then cancelled it once the cause was clear. Nothing was rolled back.

The fix

  • Drop the pending backlog when the bot starts.
  • Ignore any message or edit older than one minute.
  • Result: the update queue now sits at zero or one, and new messages are handled immediately.

What we took from it

A rewrite is rarely the hard part. The hard part is the moment it meets real traffic that has been waiting for it. We now check the pending-update count after every deploy, and we build every large bot to start clean.

Related systems

Running in production.

Moderation & Filtering
01 / 12

Moderation & Filtering

Spam, massive raids, and malicious link floods handled directly inside the group before any members read them. We use per-chat policies and heuristic rules that can be updated on the fly without a redeploy. Every removal is strictly recorded in an immutable audit log.

MTProtopattern cacheaudit log
Deploy Automation
05 / 12

Deploy Automation

Ship updates, instantly roll back, and know within seconds whether the new binary is serving traffic. Our deep health checks exercise real workloads against the database, because merely opening a listening port proves absolutely nothing.

Dockerhealth checkswatchdog
Questions

Asked and answered.

How long was the bot offline during the migration?

Between 10 and 15 seconds: the length of one Heroku dyno restart.

Did any group lose its settings?

No. The Go version reads the same database and fields as the Python one, so settings carried over untouched.

Why did the bot not reply right after the switch?

Telegram had queued over 72,000 old updates, growing by about 300 a second. The fix was to drop the backlog on startup and ignore anything older than a minute.