Implement a rate limiter and a pub/sub API
Rate Limiter
Design and implement a rate limiter with an API like boolean allow(String clientId) or boolean allow(String key). It should enforce a policy such as N requests per time window (e.g., 100 requests per minute). Discuss and ideally implement thread-safety and how you would adapt it for multiple application instances.
Pub/Sub API
Design and implement a simple Pub/Sub component, supporting publish(topic, message), subscribe(topic, subscriber), and unsubscribe(topic, subscriber). Clarify delivery semantics (best-effort vs. at-least-once), ordering per topic, and how you handle slow consumers.
AI interview prep
Core dilemma
Balancing strict resource control (rate limiting) and guaranteed message delivery (Pub/Sub) under high load and distributed conditions.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Implement a rate limiter and a pub/sub API
Rate Limiter
Design and implement a rate limiter with an API like boolean allow(String clientId) or boolean allow(String key). It should enforce a policy such as N requests per time window (e.g., 100 requests per minute). Discuss and ideally implement thread-safety and how you would adapt it for multiple application instances.
Pub/Sub API
Design and implement a simple Pub/Sub component, supporting publish(topic, message), subscribe(topic, subscriber), and unsubscribe(topic, subscriber). Clarify delivery semantics (best-effort vs. at-least-once), ordering per topic, and how you handle slow consumers.