Choosing a Sharding Strategy for Discord Bots on Discloud
Discloud's container model forces a sharding architecture choice: run Discord's ShardingManager inside one container, or deploy one container per shard. The decision hinges on fault isolation, CPU burst handling, and how much operational automation you're willing to build.
10 Aug 2026, 13:37 UTC

The container model drives your architecture
Discloud positions itself as a Discord-focused PaaS with a CLI and dashboard for deploying Node.js and Python bots. Like most container-based platforms, it allocates RAM and CPU per container — but the public documentation doesn't spell out whether a single container can run multiple shard processes or if you're expected to spin up one container per shard. That ambiguity forces a practical decision before you write any scaling code: do you run Discord's ShardingManager (or discord.py's AutoShardedBot) inside one container, or do you deploy one container per shard and let Discloud's orchestrator handle horizontal scaling?
What the platform likely provides
Most bot-hosting PaaS offerings in this tier give you a Linux container with a defined memory limit (often 512 MB–2 GB on free/low tiers) and burstable CPU. They typically expose a PORT environment variable for web servers, but Discord bots don't serve HTTP traffic — they hold persistent WebSocket connections to Discord's gateway. The platform's health checks, log aggregation, and auto-restart policies are built around that container boundary. If Discloud follows the pattern, each container gets its own cgroup, its own stdout/stderr stream, and its own restart loop.
That matters because Discord requires roughly one gateway shard per 2,500 guilds. A bot in 5,000 guilds needs two shards; one in 50,000 needs twenty. Each shard maintains its own WebSocket connection, heartbeat timer, and event dispatch loop. The memory cost per shard is modest (≈30–50 MB for a typical discord.js process), but CPU spikes during gateway reconnects or message bursts can trigger throttling on burstable instances.
Single-container sharding vs. multi-container sharding
Option A: One container, internal sharding
You start one Node.js process that imports ShardingManager and spawns N child workers. The manager coordinates shard IDs, handles resharding, and restarts crashed workers. From Discloud's perspective, it's a single application.
// shard-manager.js
const { ShardingManager } = require('discord.js');
const manager = new ShardingManager('./bot.js', {
totalShards: 'auto', // Discord tells you the count
token: process.env.DISCORD_TOKEN,
respawn: true
});
manager.on('shardCreate', shard => console.log(`Shard ${shard.id} started`));
manager.spawn();
Pros: One container to monitor, one log stream, simpler DNS/custom-domain setup if you run a health-check endpoint. Resharding happens in-process without platform API calls. Cons: A single OOM kill or unhandled exception takes down all shards. CPU bursts from twenty shards compete for the same burst credits. You can't scale individual shards independently.
Option B: One container per shard
You deploy the same bot code twenty times, each with SHARD_ID=0, SHARD_ID=1, … SHARD_COUNT=20 passed as environment variables. Your entry point reads those values and starts a single shard.
// bot.js (single-shard mode)
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
shards: [parseInt(process.env.SHARD_ID)],
shardCount: parseInt(process.env.SHARD_COUNT)
});
client.login(process.env.DISCORD_TOKEN);
You'd then use Discloud's CLI (or dashboard) to create twenty services, each pointing at the same repo but with different env vars.
Pros: Fault isolation — one shard's crash doesn't affect others. CPU and memory are guaranteed per shard. You can upgrade RAM for busy shards only. Platform-level autoscaling (if Discloud adds it) works per shard.
Cons: Twenty containers to deploy, monitor, and pay for. Resharding means creating/deleting containers and updating SHARD_COUNT everywhere. Logs are fragmented across twenty streams.
Worked example: a 12,000-guild bot on a 1 GB tier
Assume Discloud's $5/mo tier gives 1 GB RAM and burstable CPU. Your bot uses discord.js v14, runs Node 20, and averages 45 MB RSS per shard process. Five shards × 45 MB = 225 MB, leaving headroom for the manager process, Node's heap, and OS overhead. Option A fits comfortably.
Now imagine a spike: a popular command triggers a 2-second CPU burst across all shards simultaneously. In Option A, the single container's CPU credits drain fast; the platform may throttle the whole process, delaying heartbeats on every shard and risking a gateway disconnect storm. In Option B, each shard has its own CPU bucket — one shard's spike doesn't starve the others.
If you expect uneven load (e.g., one massive guild on shard 3), Option B lets you give that shard a 2 GB container while the others stay at 512 MB. Option A forces uniform resources.
Trade-off: operational complexity vs. blast radius
The multi-container approach shifts complexity from your code to your deployment pipeline. You need a way to generate SHARD_ID/SHARD_COUNT for each service — either a script that calls Discloud's API (if one exists) or a manual dashboard click-fest every time you reshard. For a bot that grows slowly, the manual tax is low. For a bot that crosses the 2,500-guild threshold weekly, you'll want automation before you adopt Option B.
Also verify Discloud's cold-start behavior. If the platform hibernates idle containers, a single-shard container that wakes on HTTP request won't help a WebSocket-only bot. You'd need a keep-alive ping or a platform guarantee of persistent WebSocket support. That's a question for Discloud's current docs or a quick free-tier test.
Actionable next step
- Deploy a minimal
discord.jsbot to Discloud's free tier (if available) using Option A withtotalShards: 2. - Run
docker statslocally (or watch the platform's metrics) during a simulated message burst —for i in {1..1000}; do curl -X POST ...; doneagainst a test command. - Check whether CPU throttling delays heartbeats (look for
WS_CLOSE4009 in logs). - If throttling appears, redeploy as two single-shard containers (Option B) and repeat the test.
That empirical check takes an hour and tells you which architecture survives your actual load profile on Discloud's actual infrastructure — no speculation required.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.