Observability, Rate Limiting, And Backpressure
Asked of: Software Engineer
Last updated

What's being tested
This topic tests whether you can design a production service that remains observable, fair, and stable when demand exceeds capacity. The interviewer is probing your ability to connect rate limiting, backpressure, and observability rather than treating them as isolated middleware features. At Meta’s scale, a strong answer must address distributed coordination, failure modes, overload behavior, cardinality, and user-visible impact—not merely name a token bucket.
Core knowledge
- Rate limiting bounds work accepted over time or concurrently. Distinguish requests per second, concurrency, bandwidth, and cost-based limits; a service may need separate limits for each resource.
- The token bucket algorithm accumulates tokens at rate up to capacity ; a request of cost succeeds when available tokens satisfy . It permits bursts up to while enforcing long-term average rate .
- A leaky bucket drains at a fixed rate, smoothing output more strictly than token bucket. Use it when downstream traffic must be shaped; use token bucket when controlled bursts improve latency and utilization.
- Fixed windows are simple but allow a boundary burst of nearly for limit . Sliding windows reduce boundary artifacts but cost more state; a rolling counter or sorted timestamps often provides a practical compromise.
- Distributed limiters need a consistent decision point. An atomic Lua script in
Redis, a strongly consistent service, or sharded local counters can work; local-only limits are cheaper but permit aggregate overshoot proportional to replica count. - Choose the limiting key deliberately: user, access token, IP, tenant, endpoint, or resource owner. Hierarchical limits can enforce both per-user and global quotas; avoid trusting spoofable headers such as
X-Forwarded-Forwithout a trusted proxy boundary. - Backpressure prevents producers from overwhelming consumers. Bounded queues, semaphore-based concurrency limits, admission control, and TCP flow control are mechanisms; an unbounded queue is not backpressure because it converts overload into memory exhaustion and latency collapse.
- Queue behavior follows Little’s Law, : average in-flight work equals arrival rate times average time in system. If arrival rate persistently exceeds service rate, queue depth and latency grow without bound; shedding work is eventually necessary.
- Load shedding should be intentional: reject low-priority work first, return
429for caller-controlled excess, return503when the service is temporarily unavailable, and includeRetry-Afterwhen retry timing is meaningful. - Observability combines metrics, logs, and traces. Track accepted/rejected requests, limiter decisions, queue depth, oldest queued age, saturation, downstream errors, and
p50/p95/p99latency, segmented by endpoint, tenant, region, and priority. - High-cardinality metrics can overload the monitoring system. Keep stable dimensions in metric labels, sample or aggregate per-user detail, and put request or trace identifiers in structured logs and traces rather than metric names.
- Alerts should detect symptoms and causes: tail latency, error rate, rejection rate, queue age, CPU, memory, and downstream saturation. A dashboard showing only average latency can hide a severe
p99regression affecting a small but important cohort. - Retry behavior interacts dangerously with overload. Exponential backoff with jitter, bounded attempts, deadlines, and idempotency reduce retry storms; never blindly retry
429,503, or timed-out writes without understanding operation safety. - A limiter’s failure mode is a product and availability decision. Fail-open preserves traffic when the limiter is unavailable but risks overload; fail-closed protects dependencies but can cause a broad outage. Prefer local fallback budgets, conservative defaults, and explicit degradation paths.
- Capacity planning should account for burst size, synchronization traffic, and hot keys. A single popular tenant can overload one shard even when cluster-wide utilization looks healthy; consistent hashing, key salting, or hierarchical aggregation may be required.
Worked example: Design a Rate Limiter for a Multi-Tenant API
I would first clarify the protected resource, tenant fairness requirement, acceptable burst size, regional topology, and whether limits are hard quotas or overload protection. I would state assumptions such as per-tenant requests per second, a bounded burst, multiple stateless API replicas, and a dependency that cannot safely absorb unlimited concurrency. I would organize the answer around policy and key selection, the limiter algorithm and distributed state, admission/backpressure behavior, and observability plus failure recovery. I would choose a token bucket with an atomic operation in Redis or a colocated limiter service, returning 429 and Retry-After when a tenant exceeds its budget. I would add a bounded per-replica work queue and a concurrency semaphore so requests admitted by the rate limiter cannot still exhaust downstream connections. The explicit tradeoff is centralized accuracy versus availability and latency: a global counter is fairer, while local buckets reduce dependency traffic but allow bounded overshoot. I would instrument allow/deny decisions, queue age, downstream saturation, and tail latency with tenant tiers rather than unbounded tenant labels. If I had more time, I would test clock skew, regional partitions, hot tenants, limiter outages, retry storms, and configuration rollout safety.
A second angle
For an asynchronous media-processing pipeline, the primary concern shifts from request rejection to controlling queue growth and protecting workers. I would use bounded queues, per-tenant concurrency quotas, priority-aware admission, and durable job state so accepted work is not silently lost. Metrics should emphasize queue age, throughput, retry counts, dead-letter volume, and time-to-completion rather than only HTTP latency. The key tradeoff is whether to delay low-priority jobs or reject them immediately when backlog threatens the completion-time objective.
Common pitfalls
Pitfall: Treating a rate limit as sufficient overload protection. A request-rate budget does not bound expensive work, concurrent database queries, response bytes, or queue memory; connect admission control to actual bottlenecks and cost.
Pitfall: Saying “use
Redis” without explaining atomicity, consistency, expiration, sharding, or failure behavior. A stronger answer specifies the token update operation, what happens during partitions, and how much temporary overshoot is acceptable.
Pitfall: Listing dashboards without an operational response. Name the alert, likely diagnosis, and mitigation—for example, rising queue age plus stable ingress suggests worker or dependency saturation, so shed low-priority work and investigate downstream latency.
Connections
An interviewer may pivot to circuit breakers, bulkheads, and adaptive concurrency limits, which complement rather than replace quotas. They may also explore distributed consistency, retry and idempotency semantics, queue durability, capacity planning, or an SLO/error-budget policy.
Further reading
- Site Reliability Engineering — Chapters on overload, cascading failures, monitoring, and handling large traffic spikes.
- The Tail at Scale — Why tail latency and fan-out make overload controls essential in distributed services.
- Release It! — Practical treatment of bulkheads, circuit breakers, timeouts, and stability patterns.
Related concepts
- Rate Limiters, Quotas, And Resource GovernanceSystem Design
- Instrumentation, Logging, And Data Quality
- Rate Limiting And Quotas For Market Data APIs
- Sliding Window Counters and Rate LimitingSystem Design
- Event Log Processing And SessionizationData Manipulation (SQL/Python)
- High-Throughput Streams, Jobs, And ObservabilitySystem Design