Build a Dual Fixed-Window Rate-Limiting Middleware

Quick Overview

Design FastAPI middleware that enforces both a global limit of 100 requests per minute and a per-domain limit of 3 requests per second. Make the API or object boundaries explicit, then cover invariants, edge cases, testing strategy, and operational trade-offs.

Build a Dual Fixed-Window Rate-Limiting Middleware

Company: Headway

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Onsite

# Build a Dual Fixed-Window Rate-Limiting Middleware Design FastAPI middleware that enforces both a global limit of 100 requests per minute and a per-domain limit of 3 requests per second. A request is accepted only when both counters have capacity. ### Constraints & Assumptions - Fixed windows use a server clock and deterministic window IDs. - Concurrent requests must not overshoot either limit. ### Clarifying Questions to Ask - Which request field defines the domain? - Do rejected requests increment counters? ### What a Strong Answer Covers - Atomic check-and-increment, keys, expiry, and response metadata. - Multi-worker correctness and boundary tests. ### Follow-up Questions - How would sliding windows differ? - How should dependency failure behave?

Quick Answer: Design FastAPI middleware that enforces both a global limit of 100 requests per minute and a per-domain limit of 3 requests per second. Make the API or object boundaries explicit, then cover invariants, edge cases, testing strategy, and operational trade-offs.

|Home/Software Engineering Fundamentals/Headway
Headway logo
Headway
Jul 25, 2026, 12:00 AM
mediumSoftware EngineerOnsiteSoftware Engineering Fundamentals
0
0

Build a Dual Fixed-Window Rate-Limiting Middleware

Design FastAPI middleware that enforces both a global limit of 100 requests per minute and a per-domain limit of 3 requests per second. A request is accepted only when both counters have capacity.

Constraints & Assumptions

  • Fixed windows use a server clock and deterministic window IDs.
  • Concurrent requests must not overshoot either limit.

Clarifying Questions to Ask Guidance

  • Which request field defines the domain?
  • Do rejected requests increment counters?

What a Strong Answer Covers Guidance

  • Atomic check-and-increment, keys, expiry, and response metadata.
  • Multi-worker correctness and boundary tests.

Follow-up Questions Guidance

  • How would sliding windows differ?
  • How should dependency failure behave?
Loading comments...