Rate Limiting And Quotas For Market Data APIs
Asked of: Software Engineer
Last updated

What's being tested
This topic tests whether you can design a distributed rate limiter that enforces customer quotas without harming latency, correctness, or availability. Bloomberg cares because market-data APIs serve high-value, latency-sensitive traffic from many clients with different entitlements, burst patterns, and contractual limits. The interviewer is probing requirement clarification, algorithm selection, distributed coordination, failure handling, observability, and the tradeoff between strict enforcement and serving stale or excess requests.
Core knowledge
-
A rate limit controls request frequency over time; a quota limits aggregate usage over a billing or entitlement period. Clarify whether limits apply per API key, user, firm, IP, instrument, endpoint, or a hierarchy of dimensions.
-
The token bucket algorithm stores tokens refilled at rate up to capacity . Each request costs tokens and succeeds when available; it permits bursts up to while maintaining long-run throughput near .
-
A leaky bucket emits work at a fixed rate and smooths bursts, while a token bucket admits bursts. Use token buckets for API admission and leaky-bucket-like queues for downstream smoothing; never hide unbounded queues behind “rate limiting.”
-
A fixed window is simple but allows boundary bursts: a client can consume requests at the end of one window and at the beginning of the next. A sliding-window counter or GCRA gives smoother enforcement with modestly greater state and computation.
-
GCRA models a theoretical arrival time rather than storing every request. For a period and burst tolerance , a request is accepted when its arrival is no earlier than the permitted theoretical time, making it efficient for high-cardinality keys.
-
A single-process limiter is insufficient behind multiple API servers. A shared store such as
Rediscan provide atomic token updates using Lua or server-side functions;Postgresrow locks are correct but generally add too much contention and latency for a hot request path. -
Distributed enforcement needs an explicit consistency choice. Strong centralized checks minimize quota overshoot but add network dependency; sharded or local limiters reduce latency and failure blast radius but can overshoot by roughly the number of replicas unless capacity is partitioned conservatively.
-
Make the state transition atomic: read current tokens and timestamp, compute refill, conditionally consume, and write the new state together. Use server-side time where possible; client clocks create inconsistencies and make replay or clock-skew behavior difficult to reason about.
-
Market-data access often has hierarchical limits: an API key may have an endpoint limit, a user limit, a firm-wide entitlement, and a provider-wide safety limit. Evaluate all applicable buckets and reject if any fails, while defining whether a failed request consumes quota.
-
Separate admission control from entitlement authorization. A client may be below its request rate but still lack permission for a security, venue, field, or data tier; authorization must not be inferred from quota state.
-
Return
429 Too Many Requestswith a stable error body andRetry-Afterwhen throttled. Include remaining-limit metadata carefully, because exposing exact global state can leak information and concurrent responses make counters approximate. -
Design for failures: decide whether an unavailable limiter fails open, fails closed, or uses a bounded local fallback. For paid or restricted data, fail closed or use a preallocated emergency budget; for low-risk public endpoints, a short-lived local fallback may preserve availability.
-
Idempotent retries matter. If a client retries after a timeout, charging each attempt can unfairly consume quota, while deduplicating requires a request identifier and bounded retention. Define whether limits count attempts, successful responses, bytes, symbols, or weighted data units.
-
Observe
allow,deny, effective rate, bucket saturation, limiter latency, store errors, synchronization lag, and overshoot. Use per-tenant dimensions and exemplars, but avoid high-cardinality unbounded metrics; sample detailed events and protect sensitive customer identifiers. -
Protect the limiter itself with bounded key cardinality, TTL cleanup, admission limits, and hot-key mitigation. A malicious client can generate many API keys or dimensions; never let attacker-controlled identifiers create unbounded state in
Redis.
Worked example
For Design a Rate Limiter for a Market Data API, I would first clarify whether the requirement is requests-per-second, weighted symbols or bytes, firm-wide contractual quotas, burst tolerance, and the acceptable overshoot during a regional failure. I would declare an initial assumption of per-entitlement token buckets, a 10,000-request-per-second steady rate, a 2-second burst, and a target decision latency below a few milliseconds. I would organize the answer around the algorithm, distributed state and atomicity, API behavior, and failure/observability strategy. The request path would authenticate the client, derive all applicable quota keys, atomically evaluate their buckets in Redis, then either forward the request or return 429. I would explicitly choose centralized sharded buckets for strict contractual limits, while acknowledging that a cross-region global bucket increases latency and creates a larger dependency. I would discuss replica ownership, failover, clock source, TTLs, hot tenants, and whether rejected requests consume tokens. A strong design would also distinguish rate limits from security entitlements and use weighted costs for expensive bulk snapshots. I would close by saying that, with more time, I would load-test burst boundaries, simulate Redis partitions and failover, and verify fairness and overshoot with production-like tenant distributions.
A second angle
For a firm-wide monthly data quota, the framing changes from short-term admission control to durable accounting and reconciliation. A fast token bucket can protect the API path, but usage should also be recorded in an append-only event stream or durable usage store with an idempotency key. The design must define calendar versus rolling periods, late responses, refunds, administrative adjustments, and what happens when the durable accounting system is unavailable. A practical architecture may use an in-memory limiter for immediate protection and asynchronous durable aggregation, with periodic reconciliation against request logs.
Common pitfalls
Pitfall: A tempting analytical mistake is to claim that a fixed-window counter provides a strict requests-per-second guarantee. It does not: boundary effects permit nearly twice the nominal rate over adjacent windows. Prefer token bucket, sliding-window, or GCRA and explain the burst semantics mathematically.
Pitfall: A communication mistake is jumping directly to
Rediscommands without clarifying what is being limited or how strict enforcement must be. Start with dimensions, units, burst tolerance, latency, multi-region behavior, and failure policy; the storage choice follows from those requirements.
Pitfall: A depth mistake is saying “use a distributed lock” and stopping there. Locks can serialize hot keys and still leave clock, failover, retry, and partial-update problems; describe an atomic state transition, bounded state, observability, and behavior when the limiter dependency fails.
Connections
An interviewer may pivot to distributed consistency, API gateway design, backpressure, circuit breakers, or idempotency. Be prepared to compare centralized coordination with local admission, and to explain how quotas interact with caching, retries, bulk requests, and entitlement services.
Further reading
- “The Token Bucket” — Cisco documentation — clear treatment of token-bucket policing and burst behavior.
- RFC 6585 — Additional HTTP Status Codes — defines
429 Too Many Requestsand retry signaling. - “Rate Limiting” — Stripe Engineering — practical discussion of distributed API limiting and limiter tradeoffs.