Rate limiting requests with tRPC in Sveltekit
Blog post from Upstash
The author describes their experience implementing an upvote feature with rate limiting in a SvelteKit app using tRPC and Redis, aiming to prevent abuse by users. After deploying the feature, the need for rate limiting became apparent due to high activity in logs and the database. The author created the 'High Five Cat' app to demonstrate the solution, which involves using tRPC middleware to manage requests, checking user IPs to apply rate limits. The solution, which is not limited to upvoting, uses a Redis-backed rate limiter from Upstash to allow only one request per minute per user. The author details the implementation process, including setting up the UI components and middleware, and discusses potential improvements and the flexibility of the approach for various use cases. The post encourages readers to consider their unique application requirements before implementation and invites them to join the Upstash Discord community for further discussion.