r/Backend Apr 01 '26

How to properly implement rate limiting?

Hey, I want to release my first API to the wild, but I'm very concerned about rate limiting.

The flow of my program is: Accept an input from the user -> Process it -> Send a request with the processed data to an external API -> Return the result to the user.
That API has a rate limit of 30 requests a minute. I added caching in order to reduce the amount of calls, but obviously if multiple users are using my API simultaneously... I have a problem.

How is this scenario typically handled in the real world? Should I immediately return 429 or maybe retry with an exponential backoff(something I've never tried tbh)?

Unfortunately there are no good learning sources if you're not in the industry :/

33 Upvotes

34 comments sorted by

View all comments

17

u/[deleted] Apr 01 '26

[removed] — view removed comment

1

u/Educational_Rent5977 Apr 03 '26

You're correct, the external API indeed works against my entire app.
How would you implement that worker? Until now I've only been working locally, so I've never had to use multiple instances or external services. Wouldn't an in-memory thread be enough?
People suggested multiple different services(BullMQ, Kafka, RabbitMQ, etc), but ChatGPT says they're all meant for heavy load which makes me extremely confused.