Core - v1.0.0
    Preparing search index...

    Interface RateLimiter<TRuntime>

    Admission control — whether a caller may proceed right now.

    An abuse control, never an accounting record. Implementations are expected to be approximate and eventually consistent, so nothing that must balance should be derived from how many times this said yes.

    What an unavailable limiter does is the one thing an implementation must not decide on its own: failing open turns a missing limiter into a capacity problem, failing closed turns it into an outage, and which is correct depends on whether the limiter is protecting an upstream or protecting a bill. It is therefore a configuration decision — see rateLimit.failOpen.

    Bayu Dwiyan Satria

    1.0.0

    1.0.0

    interface RateLimiter<TRuntime = unknown> {
        admit(runtime: TRuntime, key: string): Promise<boolean>;
        isAvailable(runtime: TRuntime): boolean;
    }

    Type Parameters

    • TRuntime = unknown

      The runtime handle the limiter is resolved from.

    Hierarchy (View Summary)

    Implemented by

    Index
    • Counts one request against a key and reports whether it is within the rate.

      Parameters

      • runtime: TRuntime

        The runtime handle.

      • key: string

        What the rate is counted per — an IP, an account, a route.

      Returns Promise<boolean>

      true when the caller may proceed.

    • Reports whether the capability is actually usable on this runtime.

      Parameters

      Returns boolean

      true when calls will reach a real backing resource.

      A capability backed by an optional resource answers false when that resource was never provisioned. Implementations must document what each method does in that state — degrade or throw — and must not vary it, since a caller choosing between two implementations is relying on the answer meaning the same thing in both.