How to Protect Resource Hungry APIs?

How to protect resource hungry APIs

In general, a web application should use some type of rate limiter to block rogue clients from overloading your servers. Typically, this is done by checking the IP of the non-logged in users and session key of the logged in users. For example, you may decide:

However, there are certain APIs which are either expensive (for example, APIs which send SMS) or very resource hungry (for example, an API which kicks off a batch process.) For these APIs, it’s critical to have specific rate limits in the place. So rather than depending on generic middleware filters, it’s important to add specific rate limits for these APIs. Here are some things you can implement:

For APIs which send Send OTP, forgot password email, etc

For APIs which send SMS or email from a request from a logged in user

An important thing to remember: These parameters like “2” appointments in “1” minute, should be configurable via application config. So that they can be changed quickly as required.

If your project uses Redis, then to store rate limiting stats you should use Redis.

Similar limitations should be placed on all APIs which kick off a batch job (for example, sending mass emails or SMS) or deal with any aspect of payment processing.

APIs that don’t deal directly with credit card, but are still monetary in nature, for example, some operation that deducts wallet balance or credits, should also have a stringent rate limit in place.

Hope this short technical read gave you a better knowledge of using APIs efficiently.

Author's Bio:

Pritam Barhate

Pritam Barhate, with an experience of 14+ years in technology, heads Technology Innovation at Mobisoft Infotech. He has a rich experience in design and development. He has been a consultant for a variety of industries and startups. At Mobisoft Infotech, he primarily focuses on technology resources and develops the most advanced solutions.

Exit mobile version