TRPC ratelimiting endpoints (race conditions)
I am currently having some problems with a race condition in my TRPC nextJS api.
Essentially what is happening is I have a
enforceGuildPermissions
method, which basically checks if the user who is making the request has permission to get the data for that guild.
The data is stored in my Redis cache for 3 seconds. This works okay sometimes, but other times because there is 3-4 different trpc requests running for a single page which are guild, role and channel. It causes the last request (channel) to get rate limited by the discord API because they are all running concurrently, this means it doesn't give my caching code chance to update it before the next one runs.
middleware route procedure:
1 Reply
function which needs to be ratelimited (using the redis cache)
A big band aid fix would be to just add an artificial wait:
But obviously this is not very elegant..
bump