Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>Rate limiter: I would probably use a hash table of this structure -- called[yyyy-mm-dd][hh-mm] and then increment the hashtable for that minute, for example, called[2022-01-02][22-01]++ and drop any entries for the last day at the end of the day.

Why on Earth? Given that the timestamp cannot randomly jump backwards, you can achieve the same results by just storing the timestamp of the first call after a reset, and the number of calls sharing the same date/hour/minute, resetting it to 0 when the minute advances.

That said, it won't be entirely what was asked, since it won't have the rolling behavior.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: