Per-Portal API Rate Limiter With Burst and Daily Caps

Last updated: November 29, 2026

Quick Overview

Implement a rate limiter for a public API where each customer account (portal) may make at most B calls in any rolling W-second window and at most D calls per UTC day. Return whether each call is allowed, which limit it hit, and how long the caller should wait.

HubSpot
Software Engineering Fundamentals
Software Engineer
HubSpot
November 29, 2026
Software Engineer
Technical Screen
Software Engineering Fundamentals
Medium

0

0

0 solved


Implement a rate limiter for a public API where each customer account (portal) may make at most B calls in any rolling W-second window and at most D calls per UTC day. Return whether each call is allowed, which limit it hit, and how long the caller should wait.

HubSpot's public APIs serve thousands of marketplace apps and integrations, and each account has both a short burst limit and a daily quota so one noisy integration cannot starve others. The interviewer checks that you pick a precise windowing scheme, isolate tenants, and return useful retry information.

What the Interviewer Expects
  • Chooses between sliding log, sliding window counter and token bucket and justifies the choice
  • Isolates state per portal so tenants never affect each other
  • Does not charge rejected calls against the quota
  • Returns a reason and a Retry-After value
  • Discusses how to move the state to a shared store across many API servers
Key Topics to Cover
rate limiting
sliding window
multi-tenancy
API design
distributed state
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you implement this in Redis so 200 API hosts share one limit?
  • The sliding log uses O(B) memory per portal. How would you reduce that?
  • How would you give a single OAuth app its own limit inside a portal's limit?
  • What do you return in headers so well-behaved clients can self-throttle?
Sharpen Your Skills on Codemia

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

Practice System Design Problems
Sample Answer
Requirements

allow(portal_id, now) returns (allowed, reason). Burst rule: at most B accepted calls with timestamps in (now - W, now]. Daily rule: at most D accepted calls per UTC day. Rejected calls do not c...

High-Level Design

For exact burst behavior I use a sliding log: a deque of accepted timestamps per portal. Expired timestamps are popped from the left before each check. The daily cap is a counter keyed by day index, r...


Submit Your Answer
Markdown supported

Related Questions