Design and Implement a Pluggable Notification Rate Limiter
Design an in-memory notification gate that composes user, team, company, count, and message-size limits without changing its core workflow.
Design and implement a notification rate limiter. Begin with can_send_notification(user_id, timestamp), which returns a boolean and counts a notification only when it is allowed. Enforce configurable limits at the user, team, and company levels, using provided helpers to resolve a user's team and company.
Then evolve the design to accept message_size and support additional rules without changing the limiter's core workflow; expose a registration boundary such as register_handler(handler). Demonstrate a user policy that allows at most four accepted messages and at most 50 total message-size units per minute.
For this exercise, assume one in-memory process serves the limiter; persistence and distributed coordination are out of scope. A known user maps to exactly one team and one company, while an unknown user is rejected.
Use a rolling 60-second window over (timestamp - 60, timestamp], with non-negative timestamps arriving in nondecreasing order per user. message_size is a positive integer. Team and company quota values are supplied as configuration rather than fixed here.
Every attempt must pass all applicable registered rules; an allowed attempt consumes every applicable user, team, and company quota atomically, while a rejected attempt consumes none. Register handlers during setup before request traffic begins.