If replicas diverge under asymmetric network delays, canonicalize first (NFKC + homoglyph folding), absorb read-heavy availability checks via Bloom filters + negative caches, and serialize mutations through linearizable Raft/Spanner range leases.
TL;DR30-second simplified summary▾
The service separates reads from writes: 500K RPS availability checks hit Edge Bloom filters and Redis negative caches in <2ms, while 5K RPS claim writes serialize through Raft range leases (CockroachDB/Spanner) keyed by NFKC/homoglyph-folded canonical_handle.
A 10-minute PENDING_CLAIM lease protects handles during multi-step signup, and transactional outboxes issue monotonic fencing tokens to downstream services.
Unicode NFKC, Case Folding & Homoglyph Canonicalization.
Why this matters: Prevent visual spoofing and duplicate-looking usernames before hitting storage.
Think of Unicode NFKC, Case Folding & Homoglyph Canonicalization as the intuition layer for Globally Unique Identity Claim Consensus: Prevent visual spoofing and duplicate-looking usernames before hitting storage.
Without canonicalization, @аlice (Cyrillic а) and @alice (Latin a) are distinct UTF-8 bytes that look identical to humans. Every check and claim runs through a deterministic Canonicalizer: strip zero-width/invisible characters, apply Unicode NFKC, map confusable homoglyphs (UTS #39 skeleton) to ASCII equivalents, and lowercase—storing both display_handle and canonical_handle (UNIQUE).
UTS #39 & NFKC Normalizer
1.Dual Storage: Store canonical_handle as the UNIQUE primary key while preserving display_handle for UI.
2.Reserved Trie: Check an in-memory Aho-Corasick trie for profanity and reserved words like 'admin'.
Deterministic Unicode and homoglyph canonicalization stops impersonation before database writes.
Why Eventual Consistency Fails & Linearizable Quorum.
Why this matters: Understand why Dynamo/Cassandra LWW loses claims and why Raft/Paxos is required on writes.
Think of Why Eventual Consistency Fails & Linearizable Quorum as the intuition layer for Globally Unique Identity Claim Consensus: Understand why Dynamo/Cassandra LWW loses claims and why Raft/Paxos is required on writes.
In an eventually consistent AP store, US-East and EU-West both accept @alice locally; during async reconciliation, Last-Write-Wins silently deletes the earlier user's account handle! Uniqueness requires CP linearizability on writes: a single Raft/Paxos leaseholder for the key's shard serializes concurrent claims, guaranteeing at most one winner.
Concurrent Claim Serialization via Raft
1.Single-Key Consensus: Uniqueness only needs linearizability per single key, scaling horizontally across Raft ranges.
2.409 Conflict: Return HTTP 409 with suggested available alternatives on contention.
Raft/Paxos consensus per key range guarantees exactly one winner under concurrent global claims.
- Problem
- How to implement Globally Unique Identity Claim Consensus without hitting unbounded tail latency, state divergence, or operational fragility.
- Naive Solution
- Use a single unpartitioned path with unbounded retries and synchronous global coordination.
- Why It Fails
- Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
- Alternatives
- Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
- Engineering Decision
- If replicas diverge under asymmetric network delays, canonicalize first (NFKC + homoglyph folding), absorb read-heavy availability checks via Bloom filters + negative caches, and serialize mutations through linearizable Raft/Spanner range leases.
- Trade-Offs
- Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
When Globally Unique Identity Claim Consensus experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?
Bloom Filter & Redis Negative Cache for 500K RPS Reads.
Why this matters: Scale live 'is this username taken?' keystroke checks 100x higher than claim writes.
Sign-up forms fire availability checks on every keystroke, creating a 100:1 read-to-write ratio (500K RPS reads vs 5K RPS writes).
An Edge Bloom Filter (~600MB for 500M handles at 1% FP) answers 'definitely available' in <0.5ms.
Bloom Filter + Redis Availability Check
1.Eventual Reads OK: Stale reads on availability checks are harmless because the final write uses Raft.
2.Debounce Clients: Debounce UI keystroke checks (250ms) to cut redundant network traffic.
Edge Bloom filters absorb the vast majority of availability checks for unclaimed handles.
Two-Phase Lease Reservation & Signup Funnel UX.
Why this matters: Hold a chosen username briefly while a user completes password/CAPTCHA/billing steps.
If @alice is free at step 1 of signup, losing it while typing a credit card at step 3 ruins UX.
A Two-Phase Lease Reservation writes a short-TTL (ttl = now + 10m) PENDING_CLAIM row keyed by (canonical_handle, reservation_token) in the Raft store.
10-Minute Pending Claim Lease
1.Anti-Squatting: Rate-limit pending reservations per IP/device fingerprint to block handle hoarding.
2.Lazy Expiry: Any new claim on an expired PENDING row overwrites it atomically.
Short-TTL lease reservations protect handles during multi-step onboarding without permanent locks.
Fencing Tokens & Saga Rollback Across Downstream Services.
Why this matters: Keep Identity, Auth, Profile, and Billing microservices consistent when claiming or renaming.
Claiming a username often spans multiple services (Identity DB -> Auth/OIDC -> Profile -> Search Index).
The Identity Consensus store issues a monotonic fencing_token alongside the commit, and writes an atomic IdentityClaimed row to a local Transactional Outbox table.
Transactional Outbox + Fencing Token
1.Fencing Prevents Races: If a user renames quickly, downstream services reject out-of-order events with lower tokens.
2.Zero 2PC Needed: Outbox + Saga avoids fragile distributed two-phase commit across microservices.
Transactional outboxes and monotonic fencing tokens keep downstream services ordered without 2PC.
Cooldown Tombstone Graveyard & Anti-Impersonation.
Why this matters: Prevent immediate hijacking of recently released or renamed usernames.
If @bob renames to @bobby, immediately freeing @bob lets an attacker hijack @bob and impersonate him to followers/mentions.
Instead, renaming moves @bob into a Cooldown Tombstone Graveyard (status = COOLDOWN, locked_until = now + 90d).
90-Day Handle Cooldown Tombstone
1.Deleted Accounts: Keep handles of banned or deleted accounts permanently tombstoned to stop impersonation.
2.Explicit History: Store handle_history(user_id, handle, retired_at) for auditability.
A 90-day cooldown graveyard prevents instant handle hijacking after renames.
Global Cache Invalidation & Split-Brain Recovery.
Why this matters: Propagate newly claimed handles to Edge Bloom Filters and Redis caches within milliseconds.
Think of Global Cache Invalidation & Split-Brain Recovery as the intuition layer for Globally Unique Identity Claim Consensus: Propagate newly claimed handles to Edge Bloom Filters and Redis caches within milliseconds.
When @alice commits in US-East, regional Redis negative caches in EU and APAC might briefly still say 'available' (harmless for correctness, slightly noisy for UX). An async Kafka -> Edge Pub/Sub stream pushes newly claimed handles to regional Redis and sets bits in Edge Bloom Filters within <500ms—while Bloom Filter rebuilds run nightly to clear expired reservations.
Async Bloom & Redis Invalidation
1.Additive Bloom: Bloom filters support bit-setting on inserts; nightly rebuilds reclaim expired bits.
2.Graceful Degradation: If Edge Redis is unreachable, availability checks fall back to DB read replicas.
Cross-region outbox streams update Edge Bloom filters and Redis caches in under 500ms.
Practice: Make the trade-off yourself.
Why must a Globally Unique Username Service use a CP linearizable store (like Raft/Spanner) on writes instead of an AP Last-Write-Wins (LWW) store?