Design a high-level system that allows multiple database nodes (masters) to handle read and write operations concurrently while ensuring strong consistency across all nodes. The system should support fault tolerance, conflict resolution, and scalable operations.
Functional Requirements (FR)
Multi-Master Writes
•Allow multiple master nodes to accept write requests simultaneously.
•All writes should be propagated to other masters to maintain a consistent state.
Read Operations
•Allow read operations from any master node.
•Ensure that reads reflect the most recent committed writes (strong consistency).
Conflict Detection & Resolution
•Detect write conflicts across masters.
•Resolve conflicts using strategies like last-write-wins, version vectors, or custom application logic.
Replication
•Replicate data changes across all master nodes.
•Support synchronous replication for strong consistency.
Fault Tolerance & Failover
•Handle node failures without data loss.
•Ensure system availability and automatic recovery.
Transaction Support (Optional)
•Support distributed transactions with ACID guarantees across masters.
Non-Functional Requirements (NFR)
•Strong Consistency: All reads must reflect the latest committed writes.
•High Availability: System should remain operational even if some masters fail.
•Scalability: Support a growing number of nodes and clients.
•Durability: Ensure no committed write is lost.
•Low Latency: Minimize write propagation and conflict resolution delays.
Core Components
API / Application Layer
•Handles client read and write requests.
•Routes operations to the appropriate master nodes.
Master Nodes
•Each node can accept reads and writes.
•Maintain a local copy of the database.
•Propagate changes to other masters.
Replication / Sync Service
•Ensures changes from one master are replicated to all other masters.
•Use synchronous replication for strong consistency.
Conflict Resolution Module
•Detects write conflicts using version vectors, timestamps, or consensus protocols.
•Resolves conflicts deterministically to maintain consistent state.
Consensus Protocol (Optional)
•Use protocols like Paxos or Raft for leaderless coordination and commit agreement.
Failure Detection & Recovery Service
•Monitor health of master nodes.
•Re-sync data for failed or recovering nodes.
Storage Layer
•Persistent storage for data and write-ahead logs (WAL).
•Ensure durability and crash recovery.
High-Level Data Flow
1.Client sends a write request → API Layer → Any Master Node → Update local database → Replicate to other masters → Commit after all confirmations.
2.Client sends a read request → API Layer → Any Master Node → Return latest committed value.
3.If conflict detected → Conflict Resolution Module → Resolve and propagate resolved value → Update all masters.
4.Node failure → Failure Detection Service → Re-sync data from healthy masters → Restore consistency.
Design Considerations
•Synchronous vs Asynchronous Replication: Use synchronous replication to ensure strong consistency, but it increases write latency.
•Conflict Resolution: Use version vectors or consensus to avoid divergent states.
•Partitioning & Sharding: Split data across multiple masters to handle scale while maintaining consistency per shard.
•Monitoring: Track node health, replication lag, and conflicts.
•Performance: Optimize for minimal latency while guaranteeing consistency using batching or pipelining replication.
✅ This is a complete HLD Problem Statement for a Multi-Master System with High Consistency, covering modules, replication, conflict resolution, fault tolerance, and scalability considerations.