Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

API Usage Limiting

Are there best practices for storing/limiting API usage? I'm looking to build a basic API using Laravel, but when trying to think about limiting daily API usage I'm getting stuck on the best approach.

Do I log each call in the database and use that to aggregate total API calls for the day to determine if the limit has been reached? What about concurrent API requests? If I want to limit to 1 API call every 5 seconds, is it best to do a database query and determine that?

Any advice would be much appreciated!

like image 885
Alix Ohrt Avatar asked Jun 06 '15 15:06

Alix Ohrt


1 Answers

This is one of those things that I like to leave up to an existing provider.

To keep things simple, put something in front of your API which has the sole responsibility of rate limiting and controlling API consumers. This is often done with an API proxy of some kind.

3scale is a good solution. It's effectively Nginx with a module for doing all the heavy lifting. http://www.3scale.net/ It's also cheap (or free depending on your load).

There are others out there like Mashery, but frankly I've had terrible luck with Mashery since Intel bought them. DNS resolution issues, skyrocketing prices, etc.

like image 100
Brad Avatar answered Oct 21 '22 11:10

Brad