Design a Geo-Distributed Leaderboard with Strong Consistency
Design a global leaderboard for a game that requires strong consistency (no stale scores). Focus on multi-master replication or single-region write dominance.
Why Interviewers Ask This
Google asks this to evaluate your ability to navigate the CAP theorem trade-offs in a real-world scenario. They specifically test if you understand that strong consistency globally often conflicts with low latency, and whether you can architect a solution like single-region write dominance or conflict-free replicated data types that prioritizes data integrity over availability when required by business logic.
How to Answer This Question
1. Clarify requirements immediately: Define 'strong consistency' as linearizability and confirm read/write patterns, such as frequent score updates versus occasional leaderboard queries. 2. Analyze constraints: Discuss the latency implications of global replication and why standard multi-master approaches might fail here due to split-brain risks. 3. Propose a primary region strategy: Suggest designating one geo-region as the primary writer for all score submissions to ensure a single source of truth, while using asynchronous replication for reads in other regions. 4. Detail the data flow: Explain how writes are queued, processed, and how stale reads are prevented during the propagation window. 5. Address failure scenarios: Describe how the system handles primary region outages using leader election protocols like Raft or Paxos to maintain consistency without data loss.
Key Points to Cover
- Explicitly acknowledging the CAP theorem trade-off between consistency and availability
- Proposing a Single-Region Write Dominance architecture to eliminate write conflicts
- Detailing a leader election mechanism like Raft or Paxos for high availability
- Explaining how to handle read-after-write consistency through routing or synchronization
- Justifying the choice based on the strict requirement for non-stale data
Sample Answer
To design a geo-distributed leaderboard with strong consistency, we must prioritize data integrity over global write availability. First, I would clarify that strong consistency implies linearizability, meaning every read returns the most recent write. Given Google's focus on reliability, I propose a Single-Region Write Dominance pattern. We designate a specific region, say US-East, as the primary master for all write operations. When a user submits a new score, the request is routed to this primary node. This ensures there is only one authoritative source of truth, eliminating the complexity of conflict resolution found in multi-master setups. For global reads, we can replicate data asynchronously to secondary regions. However, to strictly enforce strong consistency, we must implement a read-your-writes guarantee where clients are directed to the primary or a synchronous replica until the write propagates. If the primary region fails, we trigger a leader election protocol like Raft to promote a follower to primary, ensuring no data is lost. While this introduces higher write latency for users far from the primary, it guarantees that the leaderboard never displays stale scores, which is critical for competitive gaming integrity. We can mitigate latency by caching read-heavy endpoints at the edge but invalidating them immediately upon any write event to prevent serving outdated ranks.
Common Mistakes to Avoid
- Suggesting eventual consistency without explaining how to meet the strict 'no stale scores' requirement
- Ignoring the high latency penalty of forcing global strong consistency on all nodes simultaneously
- Failing to define a clear failover strategy for the primary write region
- Overcomplicating the solution with complex conflict resolution algorithms when a primary region suffices
Practice This Question with AI
Answer this question orally or via text and get instant AI-powered feedback on your response quality, structure, and delivery.
Related Interview Questions
Design a Payment Processing System
Hard
UberDesign a System for Real-Time Fleet Management
Hard
UberDesign a CDN Edge Caching Strategy
Medium
AmazonDesign a System for Monitoring Service Health
Medium
SalesforceDefining Your Own Success Metrics
Medium
GoogleProduct Strategy: Addressing Market Saturation
Medium
Google