How does Google file system deal with write failures at replicas?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Google File System (GFS) is an innovative and scalable distributed file system used to handle large data across multiple machines. Dealing with write failures at replicas is crucial for maintaining data integrity and system reliability. GFS addresses this challenge through several mechanisms, including replication, master coordination, and checksums. This article delves into these mechanisms, providing technical explanations and examples.
How GFS Handles Write Failures
Replication
In GFS, every file is divided into fixed-size chunks. Each chunk is typically replicated on three different chunk servers by default. This redundancy allows GFS to provide reliability and high availability. When a client writes data, it communicates with the master to obtain the locations of the replicas. The write operation is coordinated to ensure that data is written to all replicas successfully.
Master Coordination
The master in GFS plays a crucial role in managing chunk replicas. It tracks which chunk servers hold each chunk and detects when a chunk server becomes unavailable. If a write fails at one of the replicas:
- Failure Detection: The master periodically communicates with each chunk server to confirm its status. If a chunk server does not respond, the master marks it as unavailable.
- Re-replication: The master then schedules the re-replication of the chunks that were hosted on the failed server. This ensures that the replication factor of every chunk is maintained.
- Client Redirection: If a client's write operation fails because a chunk server is down, the master guides the client to retry the operation with a different set of chunk servers.
Write Process
During a write, the client gets a primary and secondary replica information from the master. The primary takes the charge of the write process, ensuring that writes are serialized to maintain consistency.
- Data Flow: The client pushes the data to all the replicas. Once all replicas have acknowledged receiving the data:
- Control Flow: The client then sends a write/commit request to the primary.
- Commit Phase: The primary forwards the write command to the secondaries in the same order it received the write requests from the client. If any secondary fails during this phase, it reports back to the primary, which then reports to the master for further action.
Checksums
Each chunk in GFS has an associated checksum. A checksum helps in verifying the integrity of the data. When data is retrieved, the checksum of the chunk is calculated and compared against the stored checksum.
- If the checksums match, the data is considered intact.
- If a mismatch occurs, GFS suspects corruption or a write failure at one of the replicas. The corrupted chunk is discarded, and the data is fetched from a healthy replica.
Example Scenario
Consider a scenario where a client is writing data to a set of three replicas. Suppose one of the replicas, say Replica 2, fails during the write:
- Initial Write Attempt: The client writes data to all three replicas.
- Failure at Replica 2: Replica 2 fails and notifies the primary of the failure.
- Notification to Master: The primary notifies the master of the failure at Replica 2.
- Re-replication and Retry: The master arranges for the chunk to be re-replicated on another chunk server and instructs the client to retry the write operation.
Summary Table
| Component | Role in Failure Management | Mechanism Used |
| Replicas | Provide redundancy | Replication |
| Master | Coordinate replicas and manage failures | Failure detection, Re-replication |
| Write Process | Ensure data integrity and consistency during write | Checksum, Sequential writes |
| Checksum | Verify data integrity and detect corruptions | Data validation |
Conclusion
By employing a combination of replication, robust master coordination, and data integrity checks such as checksums, GFS effectively manages write failures at replicas, thus ensuring data reliability and system resilience in the face of hardware or network failures.
Related reading
- How does gRPC connection work on kubernetes service ClusterIP
- How does High Replication Datastore implement consistent reads
- How does HLC hybrid logical clock solve Linearizability and Serializability in distributed transaction?
- How does immutable data make eventual consistency trivial?
- How does kafka ack batch AsyncProducer
- How does kafka decides the partition if I don't mention any
- How does kafka handle network partitions?
- How does Kafka store offsets for each topic?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.