For each request, the Entitlement Enforcement plugin:
- Resolves the customer’s subject key from the configured source: a Consumer, a Dev Portal application, or a request header or query parameter.
This is the same subject the Metering & Billing plugin uses to attribute usage, so both plugins agree on who’s being billed.
- Looks up the cached enforcement state for that subject in a local, per-worker cache.
- If the feature is available and the customer’s usage is within their entitlement, allows the request.
- If the feature is unavailable or the usage limit is reached, blocks the request with the configured HTTP status and message.
The following diagram shows the request’s path through the plugin:
sequenceDiagram
participant Client
participant Enforcement as Entitlement Enforcement
participant Cache as Local cache
participant Service as Upstream service
participant Metering as Metering & Billing
Client->>Enforcement: Request
Enforcement->>Cache: Check cached state
alt If allowed
Cache-->>Enforcement: Allowed
Enforcement->>Service: Forward request
Service-->>Metering: Report usage
else If blocked
Cache-->>Enforcement: Blocked
Enforcement-->>Client: HTTP error
end
note over Cache: Cache refreshed from Redis every sync_rate seconds.
Redis is refreshed from the Entitlement Access API every refresh_interval seconds.
The request only ever waits on the local cache. Redis and the Entitlement Access API are updated on their own schedules, never as part of handling a request.
Each Entitlement Enforcement plugin instance attaches to a single feature, set with config.feature.key.
To enforce more than one feature, add a plugin instance per feature on the Routes that serve it.
The plugin never calls the Metering & Billing Entitlement Access API directly from the request path.
Instead, a background timer polls the endpoint on config.refresh_interval and writes the result to Redis, and a second timer syncs Redis into each worker’s local cache on config.sync_rate.
This two-tier cache keeps the request path fast and avoids calling the Entitlement Access API on every request.
Because enforcement state is cached and refreshed on an interval, it’s eventually consistent, not real time.
A customer’s usage has to be reported and aggregated in Metering & Billing, then polled by the plugin, before enforcement reflects it.
See Cold start and fail policy for what happens the first time the plugin sees a customer, and when it can’t retrieve enforcement state at all.