John S
John S

Reputation: 17

Scaling REST API - Architecture

Our product is a rest api that we need to scale and make it redundant. Our plan is to use nginx as a load balancer and proxy which will forward the api requests to three different servers, all of which will be connected to the same MongoDB replica set.

Our api has rate limiting based on user's api key. The user will have multiple clients and all of them would be signing their requests with the same api key.

I have two questions regarding this:

  1. Multiple cron jobs need to be executed against the database. How can we make sure only one of the servers runs the crons, but if that server is down, another one runs them instead?
  2. How can we enforce the rate limits combined on all servers. How do we allow one api key to get 1000 requests per day on all three servers combined ?

Upvotes: 0

Views: 1811

Answers (1)

Sumanth
Sumanth

Reputation: 214

Multiple cron jobs need to be executed against the database. How can we make sure only one of the servers runs the crons, but if that server is down, another one runs them instead?

Consider using a Queue. All cron jobs can be picked up from a queue.

How can we enforce the rate limits combined on all servers? How do we allow one api key to get 1000 requests per day on all three servers combined?

Consider persisting a counter that gets updated every time a server receives a request from a tenant (user with a api key). Check the counter (counter < 1000) when a server receives a request to see if the they have consumed their quota.

Upvotes: 1

Related Questions