{"id":20128414,"url":"https://github.com/teamhide/simple-rate-limiter","last_synced_at":"2025-10-13T18:04:23.066Z","repository":{"id":251732585,"uuid":"838289660","full_name":"teamhide/simple-rate-limiter","owner":"teamhide","description":"Make your own rate limiter","archived":false,"fork":false,"pushed_at":"2024-08-07T14:24:50.000Z","size":74,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-13T08:29:50.345Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/teamhide.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-05T10:41:53.000Z","updated_at":"2024-08-07T14:24:53.000Z","dependencies_parsed_at":"2024-08-07T15:16:03.477Z","dependency_job_id":"4ef13f74-01f2-4d4c-823b-65c0168a3193","html_url":"https://github.com/teamhide/simple-rate-limiter","commit_stats":null,"previous_names":["teamhide/simple-rate-limiter"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teamhide%2Fsimple-rate-limiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teamhide%2Fsimple-rate-limiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teamhide%2Fsimple-rate-limiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teamhide%2Fsimple-rate-limiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teamhide","download_url":"https://codeload.github.com/teamhide/simple-rate-limiter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241572576,"owners_count":19984299,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T20:27:03.712Z","updated_at":"2025-10-13T18:04:18.020Z","avatar_url":"https://github.com/teamhide.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Simple Rate Limiter\n\nFor practice, make your own rate limiter!\n\n### [Token bucket](https://github.com/teamhide/simple-rate-limiter/blob/main/src/main/kotlin/TokenBucketRateLimiter.kt)\n**Pros**\n- 매우 간단하기 때문에 구현이 쉽다.\n- 메모리를 적게 사용한다.\n- 스파이크성으로 들어오는 트래픽을 대응할 수 있다. 버켓에 토큰이 남아있는 한 모든 요청을 수용할 수 있다.\n\n**Cons**\n- 분산 환경에서 동일 유저가 동시에 요청을 보내면 레이스 컨디션이 발생할 수 있다. (대안으로 Lua 스크립트를 활용)\n\n### [Leaky bucket](https://github.com/teamhide/simple-rate-limiter/blob/main/src/main/kotlin/LeakyBucketRateLimiter.kt)\n**Pros**\n- 제한된 큐 크기를 고려하면 효율적인 메모리를 사용한다.\n- 요청이 고정된 속도로 처리되기 때문에 안정적인 속도가 필요한 유즈케이스에 적합하다.\n\n**Cons**\n- 트래픽이 폭주하는 경우 큐에 이전 요청들이 채워지기 때문에 해당 요청들이 제시간에 처리되지 않으면 새로운 요청들이 버려진다.\n\n### [Fixed window](https://github.com/teamhide/simple-rate-limiter/blob/main/src/main/kotlin/FixedWindowRateLimiter.kt)\n**Pros**\n- 이해하기 쉽고 메모리 효율적이다.\n- 한도가 단위 시간 윈도우 끝에서만 초기화되는 유즈케이스에 가장 적합하다. 예를 들어 분당 10개의 제한이라면 매 윈도우(오전 10:00:00 ~ 10:00:59)에서 10개의 요청을 허용하여 오전 10:01:00에 한도가 초기화된다. 오전 10:00:30 ~ 오전 10:01:29 사이에 20개의 요청이 허용되었다 하더라도 오전 10:00:00 ~ 오전 10:00:59 까지가 하나의 윈도우이고 오전 10:01:00 ~ 오전 10:01:59까지는 또 다른 윈도우이기 때문에 문제가 없다. \n\n**Cons**\n- 윈도우 끝 시점에 트래픽이 급증하는 경우 실시간으로 윈도우를 추적해야하는 유즈케이스에 적합하지 않다.\n- 예제 1: 분당 10개의 제한일 때 유저가 0:59에 10개의 메시지를 받고 1:01에 10개의 메시지를 받을 수 있다.\n- 예제 2: 분당 10개의 제한일 때 요청이 10:00:30에 시작하여 10:00:59에 끝났다면 추가 요청들은 10:01:29까지 허용되지 않는다. 10:00:30에 요청이 시작되었기 때문에 추가 요청에 대한 한도는 1분 이후인 10:01:29에 초기화된다.\n\n### [Sliding window logs](https://github.com/teamhide/simple-rate-limiter/blob/main/src/main/kotlin/SlidingWindowLogRateLimiter.kt)\n**Pros**\n- 요청이 정확히 언제 발생했는지를 기록하고 그에 기반하여 판단하기 때문에 매우 정밀하게 요청을 제어할 수 있다.  \n\n**Cons**\n- 요청이 버려져도 타임스탬프를 Sorted Set에 저장하기 때문에 많은 메모리를 사용한다.\n\n### [Sliding window counter](https://github.com/teamhide/simple-rate-limiter/blob/main/src/main/kotlin/SlidingWindowCounterRateLimiter.kt)\n**Pros**\n- 구현이 비교적 간단하며 매우 높은 정확도를 가진다.\n- 각 서브 윈도우의 카운트만 저장하면 되기 때문에 메모리 사용량이 로그 방식보다 적다.\n\n**Cons**\n- 엄격하지 않은 윈도우에만 적용된다. 실제 요청 비율에 대한 근사치일 뿐이며 이는 이전 시간 윈도우의 요청이 균등하게 분포되어 있다고 가정하기 때문이다. 하지만 Cloudflare의 실험에 따르면 4억건의 요청 중 단 0.003%만이 잘못 허용/제한되었다고 하니 그리 큰 문제는 아닐 수 있다.\n\n### Article\n\nhttps://hides.kr/1152\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteamhide%2Fsimple-rate-limiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteamhide%2Fsimple-rate-limiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteamhide%2Fsimple-rate-limiter/lists"}