{"id":17130708,"url":"https://github.com/jechol/dist_limiter","last_synced_at":"2025-04-13T07:28:15.560Z","repository":{"id":43334005,"uuid":"319703816","full_name":"jechol/dist_limiter","owner":"jechol","description":"Distributed rate limiter","archived":false,"fork":false,"pushed_at":"2024-04-11T05:57:19.000Z","size":38,"stargazers_count":3,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-15T07:12:14.743Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jechol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2020-12-08T16:56:51.000Z","updated_at":"2021-02-23T20:35:05.000Z","dependencies_parsed_at":"2023-12-12T03:24:40.290Z","dependency_job_id":null,"html_url":"https://github.com/jechol/dist_limiter","commit_stats":{"total_commits":36,"total_committers":2,"mean_commits":18.0,"dds":0.02777777777777779,"last_synced_commit":"b6c1696fb51d3080db866c6b5470e360db2836d5"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jechol%2Fdist_limiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jechol%2Fdist_limiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jechol%2Fdist_limiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jechol%2Fdist_limiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jechol","download_url":"https://codeload.github.com/jechol/dist_limiter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239611993,"owners_count":19668274,"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-10-14T19:13:02.470Z","updated_at":"2025-02-23T01:31:14.584Z","avatar_url":"https://github.com/jechol.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![mix test](https://github.com/jechol/dist_limiter/workflows/mix%20test/badge.svg)](https://github.com/jechol/dist_limiter/actions)\n[![Hex version badge](https://img.shields.io/hexpm/v/dist_limiter)](https://hex.pm/packages/dist_limiter)\n[![License badge](https://img.shields.io/hexpm/l/dist_limiter)](https://github.com/jechol/dist_limiter/blob/master/LICENSE.md)\n# DistLimiter\n\nDistributed rate limiter.\n\n## Features\n\n### Distributed\nBuilt on top of `pg`, nodes which are interested in the same resource automatically form a process group. They record local `consume` timestamps and exchange those records with other nodes when being asked to `consume`.\n### Garbage collection\nMember processes automatically stop when `window` milliseconds elapsed after last `consume` on the node.\n\n### Sliding window algorithm\n`dist_limiter` implemented sliding window algorithm.\n\n\n## Usage\n\nLet's say we want to limit password challenge from IP \"a.b.c.d\" to at most 3 times a hour.\n\n```elixir\niex(1)\u003e resource = {:ip, \"a.b.c.d\", :challenge_password}                             \n{:ip, \"a.b.c.d\", :challenge_password}\niex(2)\u003e limit = {3600 * 1000, 3}\n{3600000, 3}\niex(3)\u003e DistLimiter.get_remaining(resource, limit)                                        \n3\niex(4)\u003e DistLimiter.consume(resource, limit, 1)   \n{:ok, 2}\niex(5)\u003e DistLimiter.consume(resource, limit, 1)\n{:ok, 1}\niex(6)\u003e DistLimiter.consume(resource, limit, 1)\n{:ok, 0}\niex(7)\u003e DistLimiter.consume(resource, limit, 1)\n{:error, :overflow}\n```\n\n\n## Installation\n\nAdd `dist_limiter` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:dist_limiter, \"~\u003e 0.1.1\"}\n  ]\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjechol%2Fdist_limiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjechol%2Fdist_limiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjechol%2Fdist_limiter/lists"}