InterviewLegend

Rate Limiters with Pluggable Rules

Alex Chen30 min readGuide updated
In this lesson
  • Build a notification limiter with user, team and company windows where a denied send counts nowhere
  • Turn a single limit into a rule interface that takes count and size rules
  • Run several rule types over a request log and allow a request only when all of them pass
  • Know what to say if the interviewer asks how it would scale

Cursor (Anysphere) officially runs two or three short technical screens before the onsite, though some 2026 candidates sat four or five. The first is very often the Merkle tree screen. The second rotates, and one of the problems it rotates through is a rate limiter. It comes in two versions with the same shape. You write a limiter that works for one simple rule. Then the interviewer asks for more kinds of rules, and you generalise the code so a new rule plugs in without touching the core.

Of the two, candidates met the notification version most recently. A March 2026 candidate got it in round two, right after the Merkle tree, with a function along the lines of should_send_notification. A July 2026 candidate who passed described an extensible limiter with multi-level constraints and pluggable rules, which fits this version. Reports of it run from February to July 2026. The completions API version comes from a January 2026 phone screen, described in detail by a candidate who passed.

Both are worked below in runnable Python, newest first. One signature covers part one and part two, and the tests run in part order. Get part one green before you read part two.

The Cursor angle
Part two is where this screen is graded. Cursor's recruiters list how you iterate on code, API design and low-level systems design as what they look at. A limiter that passes part one but needs a rewrite for part two loses to a plain one built on a small rule interface. One reported failure left the extension unfinished.

How the rate limiter screen runs

Expect about an hour pairing with an engineer on a backend problem, starting from a template in your language. Web search for syntax is fine, AI tools are not.

The candidate who passed the completions version in January 2026 put the bar plainly: "Goal from the interviewer was to get a working solution. Don't overindex on time and space complexity optimization." The pressure came in part two. The interviewer cared about how the main function would run every limiter and decide allow or deny. That loop is the design, so write it early and keep it short.

Every rule does two jobs. It says whether one more request would fit, and it records a request once that request is accepted. Ask every rule the first thing before you tell any rule the second. That order is how a denied request ends up counted nowhere. Recording inside the check loop is the easiest bug to write here.

One rule interface for both versions

Both problems fit the same small skeleton. A rule keeps a sliding window per key: a deque of accepted events with their cost, and a running total. Rule types differ only in what one event costs. Count rules charge one, and size or byte rules charge the message size. The decision function asks every rule, then records in every rule.

python
class WindowRule:
def units(self, size): # what one event costs; each rule type overrides it
raise NotImplementedError
def allows(self, key, timestamp, size): # drop expired events, then test the fit
...
def record(self, key, timestamp, size): # only called after every rule said yes
...
def decide(checks, timestamp, size): # checks: (rule, key) pairs for this event
if not all(rule.allows(key, timestamp, size) for rule, key in checks):
return False # denied: nothing is recorded anywhere
for rule, key in checks:
rule.record(key, timestamp, size)
return True

With this in place, a new rule type is a subclass with one method. That matches what the January 2026 candidate built to pass: an interface plus two concrete rule classes.

Asked at Cursor

Notification rate limiter with user, team and company limits

Candidates met this version through July 2026. Something like should_send_notification(user_id, timestamp) decides whether a user may get another notification. Each user is in one team and each team is in one company, and every level has its own limit over a rolling window. One version uses 3 per user, 10 per team and 20 per company over ten minutes. Treat those numbers as an example.

Part two makes it extensible. New rule types, such as a budget on message size, go in through a handler or interface without editing the core check. The class below takes the three base limits in its constructor and plugs in new rules through add_rule.

1

Notification Rate Limiter With Pluggable Rules

MediumFrequently asked
Problem
Build a NotificationLimiter. The constructor takes user_team (each user's team), team_company (each team's company), limits with the keys "user", "team" and "company", and a window in seconds. Each limit caps how many notifications one user, team or company may receive inside the window.

should_send_notification(user_id, timestamp, size) returns true when the send fits under every limit, and then records it at all three levels. Denied attempts are recorded nowhere. Sends stop counting at t + window, where t is the send's timestamp, and timestamps never go down. Part one ignores size.

add_rule(kind, scope, limit, window) plugs in a new rule for the scope "user", "team" or "company". A "count" rule caps sends like the base limits do, while a "size" rule caps the total message size accepted inside its own window. Every rule must allow a send before it goes out.
  1. NotificationLimiter({"ana": "web", "ben": "web", "cy": "api", "dee": "api", "eve": "ops"}, {"web": "acme", "api": "acme", "ops": "globex"}, {"user": 2, "team": 3, "company": 4}, 10)
  2. should_send_notification("ana", 0, 1)→ true
  3. should_send_notification("ana", 1, 1)→ true
  4. should_send_notification("ben", 2, 1)→ true
  5. should_send_notification("ben", 3, 1)→ false
  6. should_send_notification("cy", 4, 1)→ true
  7. should_send_notification("dee", 5, 1)→ false
  8. should_send_notification("eve", 6, 1)→ true
  9. should_send_notification("ben", 11, 1)→ true

Team web fills at three, so ben's second try fails. Acme fills at four, which blocks dee, while eve's company is separate. At 11 the sends at 0 and 1 have aged out, and ben has only one send on record, because the denied one never counted.

How this uses the pattern

Give each rule a deque of accepted (timestamp, units) per key plus a running total. A count rule costs 1 per send and a size rule costs the message size. Ask every rule first, then record in every rule.

Write it here, or go full screen with the problem, hints and solution beside the editor.

Notification Rate Limiter With Pluggable Rules

Loading...
Click "Run" to execute your code
The Cursor angle
Part one hides a trap. A quick version appends the timestamp to the user's list, then the team's, then finds the company is full and returns false. Now the user and the team carry a send that never went out. Check all three levels before you touch any of them. Part two is the part that gets judged, so build part one around a rule object from the start. The three base limits become three count rules with different keys, and a size budget is one small subclass. When the interviewer names a new rule, you add a class and leave should_send_notification alone.
Take it further
Per-company limits, or a fourth scope. Both are natural next asks. With rules as objects, each is a small edit. For per-company limits, give the rule a dict from key to limit and look the limit up inside allows. For a new scope such as a department, add one branch to _key that maps the user to it. The distributed version is covered at the end of this lesson.

Completions API rate limiter over a request log

This version comes from a January 2026 technical phone screen, from a candidate who passed and heard back within an hour. The input is a request log with rows something like [user_id, request_url, body_size, timestamp]. Task one is a per-user limit on one completions endpoint. Denied requests don't count, and other endpoints have no limit.

Task two opened with a scenario: "Suppose that 10 other developers come to you to build a rate limiter for their endpoints. You need to extend your interface to support patterns like this." The rules mixed request rates per second or per minute on single endpoints, a byte budget per minute on one endpoint, and an hourly cap across all endpoints. A request counts only if every rule passes.

2

Completions API Rate Limiter Over a Request Log

MediumCommonly asked
Problem
Write rate_limit(requests, rules). Each request is [user_id, url, body_size, timestamp], and the list is in timestamp order. Rules look like [kind, endpoint, limit, window], with the window in seconds. An endpoint of "*" matches every URL. Return one boolean per request, true when it's allowed.

A "requests" rule allows at most limit requests per user to its endpoint inside the window, and a "bytes" rule allows at most limit total body bytes per user there. Requests stop counting at t + window, where t is the request's timestamp, so a one-second window holds only requests with the same timestamp.

A request is allowed only when every rule that matches its URL allows it, and only allowed requests count toward any rule. URLs with no matching rule are always allowed. Part one passes a single "requests" rule, and part two passes several at once.
Inputrequests = [["u1","v1/completions/standard",10,0],["u1","v1/completions/standard",10,0],["u1","v1/completions/standard",10,0],["u1","v1/completions/standard",10,0],["u2","v1/completions/standard",10,0],["u1","v1/completions/chunked",10,0],["u1","v1/completions/standard",10,1]]rules = [["requests","v1/completions/standard",3,1]]Output[true,true,true,false,true,true,true]

Part one. u1 gets three standard requests at second 0 and the fourth is denied. u2 has its own count, the chunked endpoint has no rule, and at second 1 the window is empty again.

How this uses the pattern

Turn each rule row into an object with applies(url), allows(user, body_size, timestamp) and record(...). For each request, collect the rules that apply, ask them all, and record only if every one said yes.

Write it here, or go full screen with the problem, hints and solution beside the editor.

Completions API Rate Limiter Over a Request Log

Loading...
Click "Run" to execute your code
The Cursor angle
In the January 2026 screen the interviewer cared most about how the main function runs every limiter and decides allow or deny. That loop is the part to get right and say out loud. The candidate's interface with two rule classes maps onto request rules and byte rules here. Keep one window store for both and let each class say what a request costs. The report doesn't say whether the hourly cap is per user or shared by everyone, so ask. The version here keys every rule by user.
Take it further
A cap shared by every user. If the hourly cap means the whole service, that rule keys on a constant instead of the user id. Add an optional scope to the rule row and pick the key from it. Nothing else changes, since each rule already owns its own windows. The worked version is below the solution.

If they ask how it would scale

Candidates don't describe a distributed part in this screen, so keep this short and wait to be asked. If it comes up, the usual pushes are many stateless servers, an atomic check across all three scopes, and one huge company whose counters all land on one shard.

The single-process design carries over. Move each window into a shared store such as Redis, and run the check-all-then-record-all step as one atomic script so two servers can't both take the last slot. For a hot company, split its counter across a few keys and sum them, or give each server a slice of the limit and accept that the total can drift slightly.

Common questions

Does Cursor ask rate limiter questions in the coding interview?

Yes, as one option for the second technical screen in 2026. Candidates from January to July 2026 describe a completions API limiter and a notification limiter with user, team and company levels. The transactional key-value store and a task that speeds up an existing library also rotate through that slot.

Is this LeetCode 359 or 362?

Only the window counting overlaps. Logger Rate Limiter and Design Hit Counter teach a sliding window over one key. Cursor's version adds several levels, several rule types and the rule that a denied request counts nowhere, and the interface for new rules is what gets judged.

Can I use AI tools in Cursor's coding interview?

Not to write your code. Web search for syntax and docs is allowed in the screens, AI tools are not. The coding overview covers the exceptions.

How should I practice these two?

Build the notification class from a blank file on a timer, then add the size rule without editing should_send_notification. Do the request log next with the full five-rule set. Then explain the allow-or-deny loop out loud, since that's what the January 2026 interviewer asked about.

Key Takeaways

  • ✓Cursor's rate limiter screen has two parts. Get a limiter working, then turn it into an interface that takes new rule types.
  • ✓Ask every rule before recording in any of them, so a denied request counts nowhere.
  • ✓Share one sliding-window class and let each rule type say only what an event costs.
  • ✓Ask whether a cap is per user or shared by everyone before you code it.
Cursor interview guide

Know what Cursor asks before you walk in.

9 coding · 4 system design · 16 behavioral questions

Get Premium$49 a year · Instant access
Or start freeNo card.

Get their questions first.

The Merkle Tree Screen: Hash, Diff & SyncHad your Cursor interview?How we research

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.