Preparing your design workspace

Loading the problem and your latest saved attempt…

Design a Unique Username Registration System

Design a registration service that assigns each normalized username to at most one account under both memory-rich and disk-constrained deployments.

Problem statement

For this exercise, assume a product lets a new account choose one permanent username. A product-owned deterministic normalize(name) function converts valid input to the canonical key used for uniqueness. An availability check is advisory; only claimUsername is authoritative.

Exactly one account may ever own a normalized key, concurrent claims for the same key must produce one winner, and a retried request with the same input must return the original outcome rather than create another account or claim.

Reusing a request identifier with a different account or normalized key is rejected as an idempotency conflict. A caller that loses the response retries or queries with that same request identifier until the durable outcome is known. A successful response is returned only after the claim can survive a process restart.

Design two operating profiles with the same API and correctness contract: one in which the exact active username index fits in memory, and one in which memory is limited and the exact authority must remain disk-backed. Approximate membership structures may optimize negative checks but may never approve a duplicate.

Support 500 million claimed usernames, 20,000 claim attempts per second at peak, and bursts of 5,000 attempts per second for one popular key. Keep p99 claim latency below 250 ms in healthy operation and preserve claims indefinitely. Retain idempotency outcomes for 24 hours.

Exclude authentication, profile data, username changes, deletion and reuse, account recovery, and abuse-policy decisions.

What to build

  1. A caller can check whether a normalized username appears available, with an explicit warning that the result is advisory.
  2. A caller can atomically claim one normalized username for one account and receives won, already-taken, invalid, idempotency-conflict, unavailable, or uncertain outcomes; a same-input retry returns the original result.
  3. A caller can safely retry a timed-out claim with the same request identifier and read the one durable outcome.

At scalePractice assumption

  • The service retains 500 million exact username claims indefinitely and receives 20,000 claim attempts per second at peak.
  • One popular normalized key may receive 5,000 concurrent attempts per second, but exactly one account may ever win it.
  • A healthy authoritative claim completes within 250 ms at p99, and success is acknowledged only after restart-safe durability.
  • Idempotency outcomes remain queryable for 24 hours, while the username ownership record has no expiry or reuse path.