ExNominatim.RateLimiter (ExNominatim v3.0.0)

Copy Markdown View Source

Best-effort per-server rate limiter backed by ETS.

Tracks the last request timestamp per base_url and rejects requests that arrive before min_interval_ms has elapsed. Uses an ETS named table with write_concurrency: true so concurrent calls do not serialise through a single GenServer.

Behaviour

  • {:ok, _} responses are stored and subsequent identical requests return the cached result without hitting the rate limit.
  • Only cache misses are subject to rate limiting — the rate limiter is checked between the cache lookup and the HTTP dispatch.
  • The ETS table is created lazily on first use — no supervision tree or application callback required.
  • Errors return {:error, %{code: :rate_limited, descr: _, retry_after_ms: _}}.

Summary

Functions

Check whether a request to base_url is allowed.

Functions

check(base_url, min_interval_ms)

Check whether a request to base_url is allowed.

Returns :ok if the minimum interval has elapsed since the last request, or {:error, %{code: :rate_limited, descr: "Rate limit exceeded", retry_after_ms: retry_after_ms}} if the interval has not elapsed.

Parameters

  • base_url — the server URL string (e.g. "https://nominatim.openstreetmap.org").
  • min_interval_ms — minimum time in milliseconds between requests.