ZeroTwo: 22 GB to under 100 MB
Memory use fell from 22 GB to under 100 MB — more than 99% less — with no loss of features for 190,000 servers.
Joyn, Backend Engineer.
A team of 2–3 engineers.
About 190,000 servers.
Skills: Backend & APIs, Data & Messaging.
22 GB
<100 MB
Problem
#Joyn acquired ZeroTwo, a Discord bot serving about 190,000 servers. Its gateway-heavy design held a huge in-memory footprint of 22 GB.
Approach
#Rewrote it onto a webhook-first architecture. Commands moved off the Gateway to Discord’s HTTP interactions: each command arrives as an HTTP request and is answered over HTTP, so commands need no permanent Gateway connection.
A RabbitMQ-backed microservice bridges the webhook services and Discord Gateway events, so the bot kept full event coverage.
Before
DiscordGateway connectionsZeroTwo bot22 GB in memory
After
Discordcommands, HTTP interactionsanswered over HTTPWebhook services<100 MB
DiscordGateway eventsRabbitMQ bridgeevents the bot still needsWebhook services
$ diff -u before/zerotwo after/zerotwo--- before/zerotwo gateway-heavy, about 190,000 servers+++ after/zerotwo webhook-first-memory 22 GB+memory <100 MB-commands over the Gateway+commands HTTP interactions, answered over HTTP+events RabbitMQ bridge carries the Gateway events the bot still needs