← Headway Interview Insights

Headway·Software Engineer·Online Assessment (OA)·Intermediate

IntermediatePrefer not to say
Jun 2026Remote

Summary

Headway gave me a CodeSignal assessment for a Software Engineer role where the whole thing was one coding problem: add rate limiting to a pre-built REST API skeleton. More implementation-heavy than I expected, with some real gotchas around thread safety and window reset logic.

Questions Asked (1)

Q1

You're given a REST API project skeleton. Add rate-limiting middleware that enforces a global limit of 100 requests per minute across all endpoints and a per-endpoint limit of 3 requests per second, returning 429 when either is exceeded. Use a fixed-window approach and make sure the limiter wraps all handlers automatically so new endpoints inherit the limits without extra work.

API & IntegrationsSystem DesignTechnical Trade-offs
Author's notes

The fixed-window part tripped me up more than I expected.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and constraints, then outline a middleware-based design using fixed-window counters with two layers: a global counter and per-endpoint counters. Explain how to integrate the middleware to wrap all handlers automatically, and discuss trade-offs like memory usage, race conditions, and clock skew.

Pro tip: Mention that fixed-window has burst issues at window boundaries, and propose a simple mitigation like using two windows or a sliding window if needed. Also, emphasize thread-safety and atomic operations for counters in a concurrent environment.

1. Clarify requirements and constraints

Confirm the exact limits, window definitions, and behavior when limits are exceeded. Ask about expected traffic, concurrency, and whether distributed rate limiting is needed.

2. Design the middleware architecture

Propose a middleware that intercepts all requests, checks both global and per-endpoint limits, and returns 429 if either is exceeded. Ensure it wraps all handlers automatically, e.g., via a router-level middleware or decorator.

3. Implement fixed-window counters

Use in-memory counters with timestamps for each window. For global limit, maintain a single counter per minute; for per-endpoint, maintain a counter per endpoint per second. Use atomic operations or locks to handle concurrency.

4. Integrate and test

Apply the middleware globally so new endpoints inherit limits. Write tests to verify limits are enforced, including edge cases like concurrent requests and window resets.

5. Discuss trade-offs and scalability

Acknowledge limitations of fixed-window (burstiness) and in-memory storage (not distributed). Suggest alternatives like Redis for distributed rate limiting or sliding window for smoother enforcement.

Key Points to Mention

  • Middleware pattern for automatic wrapping of all handlers
  • Fixed-window algorithm and its trade-offs (burstiness at boundaries)
  • Thread-safety and atomic operations for counters
  • Returning 429 status code with appropriate headers (e.g., Retry-After)
  • Scalability considerations: in-memory vs. distributed (Redis) rate limiting
  • Testing strategy for rate limiters (unit, integration, load tests)

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.