TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How to be below API rate limits from multiple servers

28 pointsby ad93611over 11 years ago

4 comments

akerl_over 11 years ago
Reading the title, I was expecting to see a somewhat shady article on using multiple servers to dodge API rate limits.<p>Instead, they&#x27;ve got a pretty snazzy writeup of how to effectively keep your distributed processes working together properly. I&#x27;m curious why they didn&#x27;t pass a token rather than the actual Lua over the wire via Redis, but it certainly seems to work for them.
rryanover 11 years ago
I may be missing something but I think this could be done more cleanly with an atomic counter or semaphore [1] in Redis.<p><pre><code> 1. Have a task that releases 1 resource to the semaphore every (1.0 &#x2F; cps) seconds. 2. Workers wait to acquire a resource from the semaphore before making a call. </code></pre> Due to the rate of release being fixed at 1&#x2F;cps no worker can ever exceed the calls-per-second limit. Much simpler than sending Lua over the wire.<p>[1] <a href="https://github.com/dv/redis-semaphore" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dv&#x2F;redis-semaphore</a>
评论 #7191563 未加载
hoxover 11 years ago
Interestingly enough, Alan Shreve gave a talk at RedisConf a couple of years back detailing something very similar used on the twilio stack to rate limit draining a queue: <a href="https://inconshreveable.com/talks.html" rel="nofollow">https:&#x2F;&#x2F;inconshreveable.com&#x2F;talks.html</a>
wheatiesover 11 years ago
So they send code to Redis to make sure that they won&#x27;t increment too high? I know Redis already has a ton of functions prepackaged but this seems like it would be a good one: INCRIF.