I have a user table, with an api key column and total credits/used credits columns.
A user gets an API key, using that key, they can use my API, but only if used credits<=total credits
.
Since, this is an API, I might easily be serving dozens of requests per second. So that rules out reading/writing directly from the DB on each call in some kind of API middleware.
So, what's the right way to do it?
api-key:remaining credits
as a key value pair in redis and use that in every API call?In general, I need the solution to be highly scalable and support high concurrency (>100 reqs/sec per instance and say >100M API calls/month).
Any ideas?
Something like that. PS You also can limit transactions in seconds by key. But it is optional.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.