Per-Tenant and Global Rate Limiter for Helpdesk Integration Calls

Last updated: November 29, 2026

Quick Overview

Implement allow(integration, tenant, now) that admits a call only if the tenant has made fewer than T calls to that integration in the last W seconds and all tenants together have made fewer than G calls to it, plus retry_after(integration, tenant, now) returning how long until a call would be admitted.

Decagon
Coding & Algorithms
Software Engineer
Decagon
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Implement allow(integration, tenant, now) that admits a call only if the tenant has made fewer than T calls to that integration in the last W seconds and all tenants together have made fewer than G calls to it, plus retry_after(integration, tenant, now) returning how long until a call would be admitted.

Decagon's agents call helpdesk and CRM APIs on behalf of many customers, and those APIs throttle hard, so one busy tenant must not starve the others or trip a shared quota. The interviewer checks sliding-window correctness at the boundaries, that rejected calls do not consume quota, and a correct wait-time calculation.

What the Interviewer Expects
  • Keeps separate logs per (integration, tenant) and per integration
  • Evicts expired timestamps with a clear inclusive or exclusive boundary
  • Does not record a call that was rejected by either limit
  • Computes retry_after as the max of both limits' wait times
  • Discusses memory cost and alternatives like token buckets
Key Topics to Cover
sliding window
deque
rate limiting
multi-tenancy
fairness
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you make this work across many worker processes?
  • Memory grows with T and G. When would you switch to a sliding-window counter approximation?
  • How would you give premium tenants a reserved share of the global quota?
  • The vendor returns 429 with its own Retry-After header. How do you reconcile it with your limiter?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

A call at time now is admitted only if both windows have room. The window is (now - W, now], so a call exactly W seconds old has expired. Rejected calls are not recorded, otherwise a retrying clie...

High-Level Design

Use a deque of admit times per (integration, tenant) and per integration. On each call, pop from the left while the oldest entry is at or before now - W. If either deque is at its cap, reject. O...


Submit Your Answer
Markdown supported

Related Questions