Working with Distributed File Systems

1. Understanding DFS Architecture

ComponentRoleExamples
NameNode / MasterMetadata, namespaceHDFS NameNode, GFS Master
DataNode / ChunkserverStores data blocksHDFS DataNode
ClientReads/writes via libraryHDFS client, S3 SDK
Object storesFlat namespace, REST APIS3, GCS, Azure Blob
POSIX-likeMountable filesystemCephFS, GlusterFS, JuiceFS

2. Implementing File Replication

MethodDetail
Whole-file copyN replicas of full file
Block-level (HDFS)3× by default; rack-aware placement
Erasure codingk+m shards; tolerates m losses; ~1.5× overhead vs 3×
Cross-regionS3 CRR, geo-redundant storage

3. Understanding Block Storage

AspectDetail
Block size (HDFS)128MB or 256MB default
Object size (S3)5MB-5GB single PUT; multipart up to 5TB
Append-onlyHDFS, GFS optimized for append
Random writeLimited; designed for batch

4. Implementing Data Locality Optimization

PrincipleDetail
Move compute to dataSchedule task on node holding block
Locality levelsNODE_LOCAL > RACK_LOCAL > ANY
Used byYARN, Spark, MapReduce
Disaggregated trendCompute/storage separation (S3 + EMR)

5. Handling File Consistency

SystemModel
HDFSSingle-writer, append-only; strong
S3 (since Dec 2020)Strong read-after-write for all ops
CephFSStrong via MDS
NFSv4Close-to-open consistency

6. Implementing File Caching

LayerDetail
Client cacheLocal disk / memory (Alluxio)
Page cacheOS-level read cache
CDN edgeGeo-distributed caching
S3 + CloudFrontStandard pattern

7. Understanding Rack Awareness

Placement RuleDetail
HDFS replica 1Same node as writer (or random)
Replica 2Different rack
Replica 3Same rack as replica 2 (different node)
GoalSurvive single rack failure; minimize cross-rack traffic

8. Implementing Data Integrity Checks

MechanismDetail
Checksum (CRC32C, xxHash)Per block, verified on read
End-to-end (S3)MD5 / SHA-256 over PUT/GET
Background scrubbingPeriodic scan, repair from replica
Bit rot detectionZFS/Btrfs checksums; ECC RAM

9. Handling Node Failures

PhaseAction
DetectHeartbeat timeout (HDFS = 10.5 min default)
Re-replicateNameNode schedules new copies for under-replicated blocks
ThrottleLimit MB/s to avoid network saturation
DecommissionDrain blocks before removal

10. Understanding Read and Write Patterns

PatternOptimization
Sequential readPrefetching, large blocks
Random readSSD-backed; row-oriented formats
Append-onlyHDFS, Kafka, log-structured stores
Random writeGenerally avoided in DFS
Write-once-read-many (WORM)Compliance, archival