ADR 0012 — Cross-process rate-limit coordination: pluggable, not owned
- Status: Accepted 2026-08-27.
- Issue: #921.
- Relates to: ADR 0008
(the
register_x/get_x, single-active-instance-per-process pattern this ADR reuses verbatim); ADR 0009 / #997 (the entry-point plugin system this ADR's extension point is wired through); ADR 0011 (no hosted/managed runtime — the reason this ADR does not ship a Redis client); ADR 0004's 2026-07-29 amendment and ADR 0005 (the prior, incorrect home for this residual — see Context).
Context
#769/#858 shipped in-process rate-limit coordination: --threads N against
one endpoint shares a single RateLimiter keyed by
config.rate_limit_key(), so N worker threads pace against one bucket
instead of N independent ones. That does not extend across processes. A
Dagster sensor that launches one RunRequest per changed sync starts each
as its own OS process — N changed syncs hitting one destination endpoint in
one sensor tick means N independent buckets, each pacing to the full
configured rate. The endpoint sees up to N× the intended load.
ADR 0004's 2026-07-29 amendment folded this into #756 (remote state
backend) on the reasoning that a cross-process bucket "needs shared state."
ADR 0005 found that right about the need and wrong about the kind: a token
bucket needs low-latency atomic increment on every acquire() call, and
neither of #756's backends (object storage, no cheap compare-and-swap; a
warehouse table, worse on both counts) can serve that without the pacing
overhead becoming the bottleneck it exists to prevent. #921 was filed to
hold the problem statement on its own, with three candidate directions,
none committed.
Decision — default stays exactly as-is; cross-process coordination is a registered extension point, not a shipped backend
No behavior changes for any user who does not opt in. The existing
RateLimiter dataclass (drt/destinations/rate_limiter.py) is untouched:
same pacing algorithm, same in-process _limiter_registry, same default for
every user today. This ADR does not pick between #921's three candidates by
building one — it makes the shape of the answer "some users get real
cross-process coordination via infrastructure they already run; everyone
else keeps today's in-process pacing plus a documented fan-out caveat,"
which is not a fourth candidate but a way to stop treating the first two as
mutually exclusive:
- Formalize
RateLimiter's implicit shape as a Protocol. It already has exactly the methods a cross-process implementation would need to provide (acquire() -> None,tighten_to(requests_per_second, burst) -> None) — no changes to the class, just naming the contract explicitly so a third-party backend has something concrete to implement against, matchingRateLimitKeyed's existing structural-Protocol pattern in the same file. - A single-active-backend registry, mirroring
drt/security/base.py'sregister_permission_checker()/get_permission_checker()exactly:register_rate_limiter_backend(factory)/get_rate_limiter_backend(), defaulting to today's_default_limiter_factory(constructs the localRateLimiter). One active backend per process, not a per-key registry — the backend decides how any limiter for any key gets built; the existing per-key_limiter_registrydict is untouched and still caches whatever the active backend constructs.LimiterFactory.__call__gains a required, keyword-onlykeyparameter (config.rate_limit_key()) — the only stable identity shared across processes for "which quota is this." Without it a distributed backend has no way to derive its own shared bucket name (a Redis key, for example); the localRateLimiterignores it, since the in-process cache dict already scopes by the same string.RateLimiteritself gains a matching, inertkeyfield purely sotype[RateLimiter]keeps structurally satisfying the widened Protocol. resolve_rate_limiter()'s existinglimiter_factoryparameter is the seam — with one correction found in review. Every destination'sload(), not just test code, already passes its own module-levelRateLimitername here (sopatch("drt.destinations.<name>.RateLimiter")keeps intercepting construction in tests). Naively falling back toget_rate_limiter_backend()only whenlimiter_factory is Nonewould therefore never engage a registered backend at all: the bare, unpatchedRateLimiterclass shadows it for every real destination. The fallback instead triggers onlimiter_factory is None or limiter_factory is RateLimiter— the bare class is treated as "no genuine override," the same as omitting it, while a test's patched mock (neveris RateLimiter) or a caller's real override still wins outright. Everything else about the function (key resolution, vendor-ceiling clamping, min-wins tightening) is unchanged.- A sixth entry-point group,
drt.rate_limiter_backends, added todrt/plugins.py'sPLUGIN_GROUPS, wired exactly likedrt.permission_checkers/drt.audit_loggers: a third-party package exposes a zero-argument callable that callsregister_rate_limiter_backend(...)as a side effect. get_rate_limiter_backend()triggers plugin discovery itself — a second correction found in review. Plugin registration used to happen only in the Typer CLI's root callback (drt/cli/main.py); an installeddrt.rate_limiter_backendsentry point would therefore stay silently unregistered under the MCP server, dagster-drt, and the Airflow/Prefectrun_drt_sync()entry point — exactly the orchestrator-launched, cross-process scenario #921 is about, and confirmed empirically (parsing a built-in destination type does not itself trigger plugin loading, only a third-party one does, via #997's registry lookup). This mirrors the identical fixdrt/connectors/registry.py's_ensure_plugins_loaded()already applies to source/destination lookups: every reader of "what's currently active" funnels through aload_plugins()call (idempotent, cached per process) rather than assuming the CLI already ran it.load_plugins()itself gained a same-thread reentrancy guard — a third correction found in review. A registration callback that reads the currently active backend (a plausible pattern: wrap the existing factory rather than fully replace it) callsget_rate_limiter_backend()from inside the entry-point loopload_plugins()is already running, on the same thread._lockis a plain, non-reentrantthreading.Lock, so that nested call trying to acquire it a second time deadlocked the thread against itself — reproduced directly (a real, indefinite hang, not a theoretical race). Fixed with athreading.local()flag checked before_lockis attempted: a nested call on the same thread returns immediately with whatever has been discovered so far, while a different thread genuinely loading concurrently still blocks on_locknormally (thread-local, not a shared module-level flag, so it cannot mistake real concurrent loading for reentrancy).- The guide's example backend serialized
keyverbatim into a Redis key — a fourth correction.rate_limit_key()andresolve_rate_limiter()already documentkeyas "do not log or serialize" (it may embed a hostname, an env-var name, or other config-derived text); a distributed backend writing it unmodified into a shared, commonly-observable store contradicts that.LimiterFactory's docstring and the guide's example now derive an opaque, secret-keyed HMAC digest instead of usingkeydirectly.
drt-core ships no distributed implementation. Per ADR 0011, drt-core
does not take on a Redis (or any other shared-infrastructure) dependency by
default — not even as an optional extra bundled in this repo. An operator
who already runs Redis (or has access to their orchestrator's own
low-latency atomic-op primitive) can write a RateLimiterBackend
implementation against the Protocol above and register it via the entry
point, entirely outside drt-core. docs/guides/building-a-destination.md
already sets the precedent that drt-core documents an extension contract
without shipping every implementation of it; this ADR follows the same
shape.
#921's second and third candidates are not superseded, they compose with this one:
- Coarse pacing (
configured_rate / N) remains available to any operator today, with zero new code: set a lowerrequests_per_secondin the sync config. This ADR does not build first-class support for it (an auto-discoveredNis exactly the fragility #921 itself flagged — stale the moment fan-out changes) but does not block a future config knob for it either, should real demand justify one. - Explicit workaround, documented: this ADR's real "default" answer for
every user who does not register a backend.
docs/guides/using-webhook-trigger.mdand a new short note in the rate-limiting guide should point atstate:modifiedbatching (#772) as the way to avoid launching N processes against one endpoint in the first place, which is cheaper than coordinating N buckets after the fact.
Consequences
- Zero risk to existing users. No config default changes, no new
dependency, no new required setup.
RateLimiter's own tests are unaffected; the Protocol formalization is additive. - A real extension point exists for users who need exact cross-process correctness and already have the infrastructure for it — the "Redis" candidate from #921, without drt-core deciding for every user that they need it.
- This does not close #921's underlying tension for users with neither
Redis nor batching discipline. Anyone fanning out N processes against
one rate-limited endpoint, with no registered backend and no
state:modifiedbatching, still sees up to N× load. This ADR makes that a documented, intentional trade (subtraction: drt-core does not own the coordination infrastructure) rather than an accidental gap — the same shape ADR 0008 drew around RBAC. - Follow-up, not blocking: a reference
RateLimiterBackendimplementation (e.g. Redis-backed) could ship as a separate, optional community or drt-hub package once a real user needs one — analogous to how built-in destinations and third-party ones share one registry today. Not built speculatively here.
Freeze-scope addition to ADR 0007
| Protocol | File | Freeze scope at v1.0 |
|---|---|---|
RateLimiterBackend | drt/destinations/rate_limiter.py | Public, frozen — the cross-process rate-limit coordination extension point |