← Microsoft Interview Insights

Microsoft·Software Engineer·Onsite - System Design / Architecture·Senior

SeniorPrefer not to say
Apr 2026

Summary

Microsoft system design round, one meaty question about building an idempotency API. Felt like I had a decent grasp of the core idea but the concurrent retry edge case tripped me up more than I expected.

Questions Asked (1)

Q1

Design an idempotency API where clients send requests with a unique key, and the server guarantees retried requests return the same response without re-executing the underlying operation. Cover how you'd store keys and results, handle expiry, manage in-flight requests, and deal with concurrent retries of the same key.

System DesignAPI & IntegrationsTechnical Trade-offs
Author's notes

Started fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements (e.g., idempotency scope, TTL, consistency) and then propose a design using a persistent key-value store with atomic operations. Walk through the request lifecycle: key lookup, in-flight locking, result caching, and expiry handling, emphasizing concurrency control and failure scenarios.

Pro tip: Mention that idempotency keys should be scoped to a user or tenant to prevent cross-user collisions, and discuss how to handle partial failures (e.g., if the operation succeeds but storing the result fails) by using a two-phase commit or transactional outbox pattern.

1. Clarify Requirements and Scope

Ask about expected request volume, latency requirements, TTL for idempotency keys, and whether the operation is synchronous or asynchronous. This shapes storage and concurrency choices.

2. Design Storage Schema

Propose a table or key-value store with fields: idempotency key (unique), request hash, response status/body, state (in-progress/completed), timestamp, and TTL. Use a database like Redis or DynamoDB with atomic writes.

3. Handle Request Lifecycle

On request, attempt to insert a new record with state 'in-progress' using a conditional write. If key exists, check state: if completed, return stored response; if in-progress, return 409 or wait/poll.

4. Manage Concurrency and In-Flight Requests

Use distributed locks or atomic compare-and-swap to ensure only one request executes. For concurrent retries, either block and wait for the first to finish or return a retry-after header.

5. Handle Expiry and Cleanup

Set TTL on records based on business needs (e.g., 24 hours). Use background jobs or database TTL features to purge expired keys. Ensure that expired keys allow new operations.

Key Points to Mention

  • Idempotency key uniqueness and scoping (e.g., per user or tenant)
  • Atomic operations for key insertion and state transitions (e.g., conditional writes, Redis SETNX)
  • Handling in-flight requests: locking, waiting, or returning 409 Conflict
  • Storing response data: status code, headers, body, and possibly a hash of the request to detect misuse
  • Expiry strategy: TTL, cleanup jobs, and ensuring expired keys don't block new requests
  • Failure scenarios: what if the operation succeeds but storing the result fails? Use transactional patterns or retries

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