Many RPC providers have a limit on requests per second, meaning apps need to control how they send RPC requests. Kit and client plugins can abstract RPC requests, making it difficult to control how quickly requests are sent or how many are sent per second.
The solution for this in Kit is to use a custom transport: https://github.com/anza-xyz/kit/#custom-rpc-transports - this can affect all requests to an RPC. A custom transport could restrict an RPC to N requests per second and queue requests over this limit, to prevent an app receiving rate limits from the RPC service.
We could add support for this to our RPC plugin, eg. a maxRequestsPerSecond parameter. If passed, we would create a simple custom transport enforcing that limit, and use it for the created RPC. This would then automatically apply the rate limit to client.rpc regardless how it is called.
Many RPC providers have a limit on requests per second, meaning apps need to control how they send RPC requests. Kit and client plugins can abstract RPC requests, making it difficult to control how quickly requests are sent or how many are sent per second.
The solution for this in Kit is to use a custom transport: https://github.com/anza-xyz/kit/#custom-rpc-transports - this can affect all requests to an RPC. A custom transport could restrict an RPC to N requests per second and queue requests over this limit, to prevent an app receiving rate limits from the RPC service.
We could add support for this to our RPC plugin, eg. a
maxRequestsPerSecondparameter. If passed, we would create a simple custom transport enforcing that limit, and use it for the created RPC. This would then automatically apply the rate limit toclient.rpcregardless how it is called.