#rate-limiting #discord #discord-api #twilight #sharding

twilight-gateway-queue

Discord Gateway connection queue implementation for the Twilight ecosystem

31 unstable releases

new 0.16.0 Jan 12, 2025
0.16.0-rc.1 Feb 21, 2024
0.15.4 Sep 10, 2023
0.15.2 Apr 27, 2023
0.2.1 Nov 10, 2020

#1383 in Web programming

Download history 931/week @ 2024-09-27 609/week @ 2024-10-04 621/week @ 2024-10-11 939/week @ 2024-10-18 844/week @ 2024-10-25 819/week @ 2024-11-01 583/week @ 2024-11-08 679/week @ 2024-11-15 1082/week @ 2024-11-22 1386/week @ 2024-11-29 1053/week @ 2024-12-06 1054/week @ 2024-12-13 714/week @ 2024-12-20 587/week @ 2024-12-27 1014/week @ 2025-01-03 1062/week @ 2025-01-10

3,438 downloads per month
Used in 15 crates (2 directly)

ISC license

15KB
196 lines

twilight-gateway-queue

codecov badge discord badge github badge license badge rust badge

Rate limiting functionality for gateway IDENTIFY commands.

Discord allows bot's shards to send a limited amount of IDENTIFY commands every 5 seconds, with a daily limit from 1000 to 2000 commands, and invalidates all shard sessions upon exceeding it. Each identify interval may be filled by shards' IDs modulo max_concurrency and such a set of shards is called a bucket. See Discord Docs/Sharding.

To coordinate this, a Queue should process each identify request and shards should wait for its signal to proceed before continuing and otherwise retry. The provided InMemoryQueue never fails or cancels requests and is therefore a good starting point for custom implementations. It can also be composed to support multiple processes; see gateway-queue-http and gateway-queue for a HTTP client and server implementation, respectively.

Dependencies

~2.5–9MB
~68K SLoC