Skip to content

A basic api rate limiter implementation using the sliding window technique. Using Redis lists as the 'window.

Notifications You must be signed in to change notification settings

alioral/apiratelimiter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Rate Limiter - Sliding Window

Introduction

In order to limit API calls, this sliding window technique is implemented. So methodology is we check for users current request time and compare it with the earliest request time. After comparing we decide whether there is an opening for the incoming request.

Questions I've Answered Myself

  • Q:So assume that I've made request and filled up my API request call list. After waiting for hours, do you clear it?

    A:No! We compare it with the earliest request you made and then remove the first element and append the current time you made the request. You do not need to worry about clearing your request list. If it's been hours, every request filling up the list will be removed since each of them will be compared to your current size. So instead of thinking "having enough room" as having a clear list, think it as the items that'll be removed, on demand

  • Q: Why your test names are like "test_1, test_2" instead of more relevant names like "test_request_first", "test_request_after_rate_limit"?

  • A: Great Question! I'm using Python's incredibly simple unittest module, which is really cool but executes the tests by lexographic order (names) and that's why I wanted to make sure they were working in correct order.

Comments

Overall it was a fun challenge.

About

A basic api rate limiter implementation using the sliding window technique. Using Redis lists as the 'window.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages