Big file transfer
Difficulty: HARDCategory: HLDFrequency: 1Asked On 2025-05-01
Problem Statement
You are given a distributed system consisting of multiple server nodes connected via a 1 Gbps LAN network. Each node stores critical data in the form of files. These files are replicated across multiple nodes, with each file having a predefined replication factor (e.g., 3 replicas per file).
Your task is to design a system that ensures high availability and data durability. Specifically:
If a node is detected as unhealthy or goes down, the system must migrate all the files stored on that node to other healthy nodes, ensuring that the replication factor is maintained and no data is lost.
🧩 Requirements
Functional Requirements:
•Detect when a node becomes unhealthy or unavailable.
•Identify all files stored on the unhealthy node.
•Re-replicate these files to other healthy nodes to restore the required replication factor.
•Ensure no duplicate replication if some replicas already exist on other nodes.
•The migration should be network-efficient, utilizing the available 1 Gbps LAN bandwidth wisely.
Non-Functional Requirements:
•Fault-tolerant design with no single point of failure.
•Low-latency detection and response to node failures.
•Scalable as the number of nodes and files grows.
•Support concurrent failures (e.g., more than one node failing simultaneously).
•Ensure data consistency and integrity during migration.
Solution
❓ Open Questions to Explore
🧭 System Roles
1.Single or Multiple Controllers?
•Should the system have a single controller node or multiple (possibly redundant) controllers?
•What are the trade-offs in availability and complexity?
2.Controller Failure Handling
•What happens if the controller node crashes mid-transfer?
•Should we implement leader election, persistent state, or use a distributed consensus mechanism?
💀 Node Health & Failure Detection
1.Detecting Unhealthy Nodes
•How does the controller identify that a node is unhealthy or has gone offline?
•Is there a heartbeat mechanism, timeout-based detection, or metrics threshold?
2.Source Selection Strategy
•Once a node is deemed unhealthy, how does the controller determine which healthy node(s) to copy the files from?
•Should it prioritize nodes based on network proximity, disk load, or recent replication success?
🎯 Target Node Assignment
1.Target Node Selection
•On what basis does the controller decide which nodes should receive the replica or replacement of the lost data?
•Should it consider storage utilization, rack diversity, or replication factor requirements?
📁 Transfer Mechanics
1.Transfer Source
•Should the copy be initiated from the unhealthy node (if still accessible) or exclusively from healthy replica nodes?
2.Transfer Initialization & Monitoring
•Who initiates the file transfer — the controller or the destination node?
•How is the transfer monitored and verified in real time?
3.Progress Updates
•How frequently should the receiving node send progress/status updates to the controller?
•Should there be a timeout or retry mechanism?
📦 Chunking Strategy
1.Chunking vs. Whole File Transfer
•Is the file transferred as a single blob or in smaller chunks?
•What are the benefits of chunk-based transfer (resumability, parallelism)?
2.Optimal Chunk Size
•Given LAN speed (1 Gbps) and metadata overhead, what is the optimal chunk size?
•How do we balance:
•Small chunks → better parallelism, more metadata
•Large chunks → less overhead, harder recovery on failure
3.Chunk Metadata Design
•What format will the metadata follow?
•Should it include SHA-256 per chunk, size, index, etc.?
🔄 Threading and Performance
1.Thread Count and Efficiency
•How many threads should each node use for downloading/uploading chunks?
•Is there a performance plateau after a certain thread count (e.g., due to CPU or I/O limits)?
2.Thread Saturation
•Can too many threads hurt performance due to context switching or resource contention?
🛡️ Fault Tolerance and Recovery
1.Partial Transfer Recovery
•If a transfer is interrupted, can it resume from the last completed chunk?
•Should the system persist temporary progress checkpoints?
2.Verification and Final Check
•How do we verify the integrity of the copied file or chunks?
•Should the controller perform hash comparisons post-copy?
📚 Additional Design Questions
1.Replication Policy
•How many replicas should we maintain per file?
•Should this number be configurable at runtime?
2.Data Consistency
•How do we ensure that all nodes have the same consistent version of the file, especially if transfers happen concurrently?
3.Security and Authorization
•Should file transfers be authenticated?
•Do nodes require permission from the controller to initiate transfer?
4.