Api Design easy
Your API enforces 100 requests/minute per API key. What headers should responses include to help clients manage their usage?
- A Include X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset headers.
- B Only return a 429 Too Many Requests status code when the limit is exceeded.
- C Use the Retry-After header with a timestamp for when the user is unblocked.
- D Send an email alert to the user when they approach 90% of their limit.
Answer: A. Include X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset headers.
Returning rate limit headers (like `X-RateLimit-Limit`, `X-RateLimit-Remaining`, and `X-RateLimit-Reset`) is a best practice for API usability. It allows clients to proactively manage their request rate and avoid hitting the limit (which would result in a 429 error). This transparency improves the developer experience and system stability.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- You're designing a REST API for a blog. Which endpoint best represents 'get all comments for post 123'?
- A client wants to update only the 'status' field of an order, leaving other fields unchanged. Which HTTP method is most appropriate?
- A client calls POST /users with valid data, and the user is created. What status code should the server return?
- A client retries a failed 'POST /payments' request due to network timeout. The server receives the request twice. Without idempotency handling, what can happen?
- An API returns 10,000 products. Returning all in one response is impractical. Which pagination approach is simple and stateless?
- Your API serves both mobile apps and third-party integrations. Which authentication method is most appropriate?