custom prompt

Prompt

Answer all five parts. Follow the output format exactly. ## Spec: Multi-tenant rate limiter - Each tenant has a token bucket: capacity 3, refill 1 token/second, refilled continuously, starting full at t=0. - A request consumes 1 token if at least 1 is available; otherwise it is rejected (REJECT_TENANT). - Global limit: a request at time t is rejected (REJECT_GLOBAL) if 4 or more requests were already accepted in the window (t − 1.0, t]. The window is open on the left, closed on the right. - The global check runs first. A globally rejected request does not touch the tenant's bucket. - Requests are processed in timestamp order; ties are broken by tenant ID alphabetically. - Product note: no tenant may have more than 2 requests accepted in any 0.5-second span. Trace (seconds): Tenant A: 0.0, 0.1, 0.2, 0.3, 1.2, 1.3, 2.5, 2.6, 2.7, 5.0 Tenant B: 0.0, 0.05, 0.15, 1.0, 1.25 ## Part A — Spec review (max 120 words) Identify any inconsistency in the spec, explain it, and state how you resolve it. Do not silently pick one interpretation. ## Part B — Simulation Process the trace by hand. Output a markdown table with exactly these columns: | # | time | tenant | result | tokens_after | result ∈ {ACCEPT, REJECT_GLOBAL, REJECT_TENANT}. tokens_after = the tenant's bucket after the request, to 2 decimals; write "—" for REJECT_GLOBAL. Then give both tenants' token counts at t=5.0. ## Part C — Implementation (Java 17) - Thread-safe. No libraries except JUnit 5. - Inject the clock; no System.currentTimeMillis() or Instant.now() inside the limiter. - No float or double anywhere in the token math. - One public class per file; show each file under its path as a heading. - Include a JUnit test that replays the Part B trace and asserts every result. - In 5 sentences or fewer, justify your concurrency strategy and name one contention bottleneck. ## Part D — Distributed reasoning The limiter runs as 3 replicas behind a strict round-robin load balancer with no shared state. 1. What maximum burst and sustained rate can one tenant actually get? What global throughput is possible per 1-second window? 2. Propose a Redis-based design that makes both limits exact. Name one failure mode and its mitigation. ## Part E — Self-check List any part where you are uncertain, and why. End with exactly one line: SUMMARY: accepted=<n> global_rejects=<n> tenant_rejects=<n>

Drag to resize

Response not available

Drag to resize
Drag to resize
Drag to resize
Drag to resize