How do you keep rate limits consistent when the API scales to several tasks?
After this you can answer: How do you keep rate limits consistent when the API scales to several tasks?
Say it in 30 seconds
Section titled “Say it in 30 seconds”The deeper answer
Section titled “The deeper answer”A token bucket permits a burst up to capacity and restores tokens over time. Login has capacity twenty and one token per three seconds; booking has capacity ten and one per second. The script updates the bucket atomically and sets expiry so inactive identities do not accumulate forever.
The limiter hashes identities in key names. That avoids readable raw IPs or user IDs there, but hashing does not automatically make an identifier anonymous or remove privacy obligations. Rejected requests carry a computed retry delay through the API error mapping.
The client IP is only useful if proxy trust matches the deployment path. Trusting too few hops can group everyone under a load-balancer IP. Trusting too many can allow caller-supplied forwarding data to influence the result. Even a correct IP can represent an office network with many legitimate users. Production policies need layered identity and evidence rather than simply increasing every limit.
Counter-questions
Section titled “Counter-questions”What if Redis is slow or unavailable?
Why not keep a Map in each API task?
Would you use the same identity for every operation?
Where in MiniTickets
Section titled “Where in MiniTickets”Read Rate limits inventory gate, then inspect the rate-limiter piece →.
apps/api/src/queries/rate-limits.ts → takeToken
See the real users get 429 case.
Read this book online: https://book.theversehub.in/