Sharding for bot in a single very large server #6584

Closed
opened 2025-06-18 21:29:17 +02:00 by spAnser · 9 comments
spAnser commented 2025-06-18 21:29:17 +02:00 (Migrated from github.com)

Type of feature request

Other

Description of the feature you're suggesting

I use Red in a single server with around 300k members. The server recently had a very large influx of members, >18k in a single day, with a large portion occurring within just a few hours, which ended up leaving me with a full IP ban to discord servers that lasted nearly a full day.

When I reached out to support they responded with the following:

Thank you for your patience and for writing back. So you can indeed implement sharding even on a single IP. In fact, at your scale it is definitely something you should look into to reduce rate limit issues. Your server is approaching 300,000 members, which requires sharding to stay compliant within our gateway and rate limit expectations. Even though you're self-hosting:

  • You can shard a bot from a single machine — it’s about how you split and manage gateway connections logically, not physically.
  • If using discord.js, discord.py, or similar libraries, look into their built-in sharding managers (e.g., ShardingManager).
  • Ensure your outbound API calls are rate-limited per-route by our x-ratelimit headers and avoid parallel calls wherever possible. (Try batching requests or delaying requests by a bit)

And finally, as your app continues to scale, operating off of a single IP will become increasingly difficult. We would encourage exploring the moving to a more scalable environment with for example, rotating IPs, elastic bandwidth, or containerized sharding support.

Looking at other issues to figure out how to enable sharding #3096. It seems like it is entirely controlled by server count, not by member count and is out of my control.

What the server mods and I determined was the cause was having the bot send a message with full user info into a channel on join.

I think this is a built in cog? So we disabled it like so:

<prefix>modlog toggle false member_join

I'm curious if sharding is something that needs to be implemented based on member count in addition to server count like support is saying, or if maybe the member join logging should be throttled in some way.

Anything else?

No response

### Type of feature request Other ### Description of the feature you're suggesting I use Red in a single server with around 300k members. The server recently had a very large influx of members, >18k in a single day, with a large portion occurring within just a few hours, which ended up leaving me with a full IP ban to discord servers that lasted nearly a full day. When I reached out to support they responded with the following: > Thank you for your patience and for writing back. So you can indeed implement sharding even on a single IP. In fact, at your scale it is definitely something you should look into to reduce rate limit issues. Your server is approaching 300,000 members, which requires sharding to stay compliant within our gateway and rate limit expectations. Even though you're self-hosting: > > * You can shard a bot from a single machine — it’s about how you split and manage gateway connections logically, not physically. > * If using discord.js, discord.py, or similar libraries, look into their built-in sharding managers (e.g., ShardingManager). > * Ensure your outbound API calls are rate-limited per-route by our x-ratelimit headers and avoid parallel calls wherever possible. (Try batching requests or delaying requests by a bit) > > And finally, as your app continues to scale, operating off of a single IP will become increasingly difficult. We would encourage exploring the moving to a more scalable environment with for example, rotating IPs, elastic bandwidth, or containerized sharding support. Looking at other issues to figure out how to enable sharding #3096. It seems like it is entirely controlled by server count, not by member count and is out of my control. What the server mods and I determined was the cause was having the bot send a message with full user info into a channel on join. I think this is a built in cog? So we disabled it like so: ``` <prefix>modlog toggle false member_join ``` I'm curious if sharding is something that needs to be implemented based on member count in addition to server count like support is saying, or if maybe the member join logging should be throttled in some way. ### Anything else? _No response_
yamikaitou commented 2025-06-18 21:37:18 +02:00 (Migrated from github.com)

Sharding is handled by dpy, not Red. Also, the cog you mention, that is ExtendedModLog which is a 3rd party cog.

Sharding is handled by dpy, not Red. Also, the cog you mention, that is ExtendedModLog which is a 3rd party cog.
TrustyJAID commented 2025-06-18 21:43:24 +02:00 (Migrated from github.com)

To add onto this, Red's default behaviour with discord.py's AutoShardedClient will attempt to get the recommended number of shards from discords' gateway. Theoretically discord should be telling the bot it might need 2 shards instead of 1.

Sending 18k messages in 1 channel in 1 day is a lot and would very easily start hitting discord's rate limits regardless of shard count.

To add onto this, Red's default behaviour with discord.py's AutoShardedClient will attempt to get the recommended number of shards from discords' gateway. Theoretically discord should be telling the bot it might need 2 shards instead of 1. Sending 18k messages in 1 channel in 1 day is a lot and would very easily start hitting discord's rate limits regardless of shard count.
spAnser commented 2025-06-18 21:43:43 +02:00 (Migrated from github.com)

Sharding is handled by dpy, not Red. Also, the cog you mention, that is ExtendedModLog which is a 3rd party cog.

I was afraid that might've been it. I figured it's name would've been extendedmodlog not just modlog in the cog list.

> Sharding is handled by dpy, not Red. Also, the cog you mention, that is ExtendedModLog which is a 3rd party cog. I was afraid that might've been it. I figured it's name would've been `extendedmodlog` not just `modlog` in the cog list.
yamikaitou commented 2025-06-18 21:45:09 +02:00 (Migrated from github.com)

Sharding is handled by dpy, not Red. Also, the cog you mention, that is ExtendedModLog which is a 3rd party cog.

I was afraid that might've been it. I figured it's name would've been extendedmodlog not just modlog in the cog list.

It is, but we also provide a cog named ModLog. The modlog command though is part of the ExtendedModLog cog, not the built-in ModLog cog

> > Sharding is handled by dpy, not Red. Also, the cog you mention, that is ExtendedModLog which is a 3rd party cog. > > I was afraid that might've been it. I figured it's name would've been `extendedmodlog` not just `modlog` in the cog list. It is, but we also provide a cog named ModLog. The `modlog` command though is part of the ExtendedModLog cog, not the built-in ModLog cog
spAnser commented 2025-06-18 21:51:13 +02:00 (Migrated from github.com)

To add onto this, Red's default behaviour with discord.py's AutoShardedClient will attempt to get the recommended number of shards from discords' gateway. Theoretically discord should be telling the bot it might need 2 shards instead of 1.

Sending 18k messages in 1 channel in 1 day is a lot and would very easily start hitting discord's rate limits regardless of shard count.

Yeah 18k in a day probably wasn't ideal anyways. I was thinking of other solutions for joins already.

I just wasn't sure if there was anything from the discord support email that was considered new-ish seeing as all other sharding documentation seems to only mention server count not member count.

If there is no action to be made to Red I'm good with the issue being closed. I just wanted to be sure.

> To add onto this, Red's default behaviour with discord.py's AutoShardedClient will attempt to get the recommended number of shards from discords' gateway. Theoretically discord should be telling the bot it might need 2 shards instead of 1. > > Sending 18k messages in 1 channel in 1 day is a lot and would very easily start hitting discord's rate limits regardless of shard count. Yeah 18k in a day probably wasn't ideal anyways. I was thinking of other solutions for joins already. I just wasn't sure if there was anything from the discord support email that was considered new-ish seeing as all other sharding documentation seems to only mention server count not member count. If there is no action to be made to Red I'm good with the issue being closed. I just wanted to be sure.
Flame442 commented 2025-06-18 23:43:36 +02:00 (Migrated from github.com)

I believe you received incorrect information (or at least, potentially misleading information) from Discord support. Sharding allows your bot to split its workload across multiple processes (potentially including multiple machines) by specifying a flag when starting up the bot and connecting to Discord. When you enable sharding, the servers the bot can see are split up and assigned to particular processes based on the configured number of shards and shard ID specified for that particular bot. Gateway events are then sent to only the process assigned to the shard associated with that specific server (using a formula based on the server ID). There is no way to distribute the load of a single server across multiple shards.
Ref: Discord Developer Docs

As a result, it is impossible for sharding to assist with the particular situation you are describing. Your best bet is to limit the number of ways Red responds to input, limiting it to only the most important features such as moderation and commands. Join notifications and other auxiliary event-based functions should be disabled for a server at that scale. I also will warn you that Red is not optimized for large servers or a large number of servers, rather it is designed to be expansive and customizable. This will cause it to perform worse under these conditions than a bot designed for a single specific task.

I believe you received incorrect information (or at least, potentially misleading information) from Discord support. Sharding allows your bot to split its workload across multiple processes (potentially including multiple machines) by specifying a flag when starting up the bot and connecting to Discord. When you enable sharding, the *servers* the bot can see are split up and assigned to particular processes based on the configured number of shards and shard ID specified for that particular bot. Gateway events are then sent to only the process assigned to the shard associated with that specific server (using a formula based on the server ID). There is no way to distribute the load of a *single server* across multiple shards. Ref: [Discord Developer Docs](https://discord.com/developers/docs/events/gateway#sharding) As a result, it is impossible for sharding to assist with the particular situation you are describing. Your best bet is to limit the number of ways Red responds to input, limiting it to only the most important features such as moderation and commands. Join notifications and other auxiliary event-based functions should be disabled for a server at that scale. I also will warn you that Red is not optimized for large servers or a large number of servers, rather it is designed to be expansive and customizable. This will cause it to perform worse under these conditions than a bot designed for a single specific task.
Kowlin commented 2025-06-19 05:19:55 +02:00 (Migrated from github.com)

BACK IN MY DAY!! (Yes Really me!) I've gotten Red to work on Official Fortnite where the max member cap at the time was 500k, and Fortnite was in its prime, without any real changes. All that was required was a powerful machine to handle all the ingest of data, and us limiting what the bot would do and respond on. Our bot was first and foremost a moderation bot. And then everything else.

So while its not recommended, since its mostly me screaming that its not recommended. It is doable is you drop certain features. Like welcoming, fun activities, etc etc.

BACK IN MY DAY!! (Yes Really me!) I've gotten Red to work on Official Fortnite where the max member cap at the time was 500k, and Fortnite was in its prime, without any real changes. All that was required was a powerful machine to handle all the ingest of data, and us limiting what the bot would do and respond on. Our bot was first and foremost a moderation bot. And then everything else. So while its not recommended, since its mostly me screaming that its not recommended. It *is* doable is you drop certain features. Like welcoming, fun activities, etc etc.
spAnser commented 2025-06-19 14:26:20 +02:00 (Migrated from github.com)

BACK IN MY DAY!! (Yes Really me!) I've gotten Red to work on Official Fortnite where the max member cap at the time was 500k, and Fortnite was in its prime, without any real changes. All that was required was a powerful machine to handle all the ingest of data, and us limiting what the bot would do and respond on. Our bot was first and foremost a moderation bot. And then everything else.

So while its not recommended, since its mostly me screaming that its not recommended. It is doable is you drop certain features. Like welcoming, fun activities, etc etc.

Yeah it isn't perfect, but this is not a new setup of the bot. We actually use a mix of bots to handle different aspects and have been slowly moving things off Red as we can. User join logging is probably just the next thing to turn off. We have actually been using Red since 2017 when I took ownership of the Clash of Clans server.

> BACK IN MY DAY!! (Yes Really me!) I've gotten Red to work on Official Fortnite where the max member cap at the time was 500k, and Fortnite was in its prime, without any real changes. All that was required was a powerful machine to handle all the ingest of data, and us limiting what the bot would do and respond on. Our bot was first and foremost a moderation bot. And then everything else. > > So while its not recommended, since its mostly me screaming that its not recommended. It _is_ doable is you drop certain features. Like welcoming, fun activities, etc etc. Yeah it isn't perfect, but this is not a new setup of the bot. We actually use a mix of bots to handle different aspects and have been slowly moving things off Red as we can. User join logging is probably just the next thing to turn off. We have actually been using Red since 2017 when I took ownership of the Clash of Clans server.
Jackenmen commented 2025-06-19 14:41:17 +02:00 (Migrated from github.com)

As Flame explained, this is not possible - Discord's sharding partitions the events based on the server ID. To my knowledge, you can't split the load into chunks smaller than a single server's load. The response you got from support seems to contradict that, but I believe this is likely to be a mistake from the support agent who responded to your question.
Since we cannot implement something that the API gateway does not support, I'm going to close this issue.

As Flame explained, this is not possible - Discord's sharding partitions the events based on the server ID. To my knowledge, you can't split the load into chunks smaller than a single server's load. The response you got from support _seems_ to contradict that, but I believe this is likely to be a mistake from the support agent who responded to your question. Since we cannot implement something that the API gateway does not support, I'm going to close this issue.
Sign in to join this conversation.
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot#6584
No description provided.