Preparing your design workspace

Loading the problem and your saved attempt…

Design an In-Memory Action Rate Limiter

Model a reusable in-process component that decides whether a subject may perform a configured action.

For this exercise, assume an application needs an in-memory library that rate-limits named actions for string subject IDs. A caller submits a subject ID, action name, positive request cost, and timestamp, and receives an allow-or-reject decision with remaining capacity and retry guidance.

Each action has a configurable capacity and time window. An allowed request consumes its cost atomically; a rejected request consumes nothing. Policy changes affect later decisions and do not rewrite already recorded usage.

Invalid costs, unknown actions, and timestamps that move backward for the same subject-action pair must produce explicit errors. Design the object model, contracts, and interaction flows. One process and caller-supplied timestamps are in scope; persistence, networking, and cross-process coordination are out of scope.

Do not implement the component.