#discord #discord-api #twilight


Discord Gateway connection queue implementation for the Twilight ecosystem

27 releases (14 breaking)

0.15.2 Apr 27, 2023
0.15.1 Feb 26, 2023
0.15.0-rc.1 Jan 8, 2023
0.14.0 Nov 14, 2022
0.2.1 Nov 10, 2020

#535 in Web programming

Download history 622/week @ 2023-02-04 479/week @ 2023-02-11 595/week @ 2023-02-18 664/week @ 2023-02-25 486/week @ 2023-03-04 436/week @ 2023-03-11 478/week @ 2023-03-18 393/week @ 2023-03-25 286/week @ 2023-04-01 773/week @ 2023-04-08 365/week @ 2023-04-15 525/week @ 2023-04-22 646/week @ 2023-04-29 581/week @ 2023-05-06 444/week @ 2023-05-13 494/week @ 2023-05-20

2,205 downloads per month
Used in 9 crates (2 directly)

ISC license

23K SLoC


Ratelimiting functionality for queueing new gateway sessions.

The gateway ratelimits how often clients can initialize new sessions. Instances of a queue are given to shards so that they can request to initialize a session.

Queue implementations must point to the same broker so that all shards across all shard groups, processes, and other forms of multi-serviced applications, can work together and use the same ratelimiting source. That is, if two shard groups are in two different processes, then the the two processes must use some unified form of ratelimiting: this can either mean using IPC to communicate ratelimiting or a broker.

Provided queues

Most users only need the [LocalQueue]: it's a single-process queue for smaller bots. Larger bots need the [LargeBotQueue], which supports single-process Sharding for Large Bots through the use of bucket releasing.

By default, the gateway's stream module and Shards use the [LocalQueue]. This can be overridden via the ShardBuilder::queue configuration method.

Advanced use cases

Large bots, and smaller bots out of design, may need to implement their own queue. The most common reason to need this is if you have shard groups in multiple processes. A broker to manage ratelimiting across shard groups is required, so a [Queue] trait is provided that shards can use to make requests to create sessions.



The twilight-http feature brings in support for [LargeBotQueue].

This is enabled by default.


~261K SLoC