DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk8 min

Build a Go Distributed Filesystem: Start with an HDFS-Style Design

Build a small HDFS-inspired filesystem in Go by separating metadata from block storage, defining explicit write and commit semantics, and adding replication only after recovery behavior is clear.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A small HDFS-style distributed filesystem in Go needs three cooperating parts: a metadata coordinator, storage nodes, and a client that moves file data directly between itself and those nodes. Start with one coordinator, immutable files, and a clearly defined commit rule. Add replication and failure recovery only after the basic block and metadata flows work.

What an HDFS-style design means

HDFS separates metadata decisions from file-data transfer. Its NameNode manages the namespace and block mappings; DataNodes store blocks and serve reads and writes. Clients consult the NameNode for metadata and locations, then transfer data with DataNodes rather than routing file contents through the NameNode.

As an Amazon Associate I earn from qualifying purchases.

You can adapt that shape for a Go project without implementing Hadoop’s protocols or claiming compatibility. Treat the coordinator as the authority for the filesystem’s logical view, and storage nodes as holders of block bytes. The client connects both sides.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Metadata coordinator: owns paths, file records, block order, replica locations, write state, and storage-node liveness.
  • Storage node: persists and serves blocks on local disk, checks their integrity, reports its inventory, and carries out authorized replication or deletion work.
  • Client: asks the coordinator where blocks belong, transfers data directly with storage nodes, and reports operation results.

This division keeps bulk data off the coordinator’s request path. It also means metadata and block operations must be coordinated: a block can exist on disk without being part of a committed file, and metadata can become stale if a node fails.

Choose a small, explicit metadata model

Define the on-disk and in-memory model before building RPC handlers. A useful starting point is a file record containing a stable file identity, canonical path, ordered block IDs, and a lifecycle state. Each block record needs its length, checksum, and known replica locations. Keep node records for identity, last heartbeat, and reported inventory.

The exact schema is a project choice, not a Hadoop requirement. The important distinction is between the file’s logical ordering of blocks and the physical nodes that currently hold each block. A file can therefore be reconstructed in order even when its blocks are distributed across several machines.

Represent an in-progress write separately from a committed file. For example, a write can move through states such as creating, uploading, and committed, with failure or cleanup states as needed. Do not let ordinary reads resolve an unfinished file unless you deliberately define partial-read semantics.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Define the data path before the API

A first version can use a small set of coordinator operations: create a file, request a block write plan, commit a completed file, resolve a path for reading, and report node status or inventory. Storage-node operations can accept a block, return a block, report inventory, and perform coordinator-authorized replication or deletion.

Use stable operation and block identifiers. If a client retries after a timeout, the receiver should be able to recognize the same operation rather than accidentally create a second file or duplicate logical block. Define authorization between components as part of the protocol; do not allow a client to issue arbitrary storage-node deletion or replication commands.

How to write a file safely

For a teaching implementation, immutable files with one writer at a time are a useful scope choice. HDFS documentation describes write-once files with a single writer, while allowing append and truncate exceptions in its current architecture. You can omit those exceptions initially to avoid concurrent-writer and partial-update complexity.

  1. Create: The client asks the coordinator to create a path. The coordinator verifies the path and returns a write ID and a write plan. The plan identifies block IDs and target storage nodes, plus the replication and acknowledgement policy for this write.
  2. Split and transfer: The client divides the input into the planned blocks and sends each block to its target node, or to a defined node-to-node replication pipeline. The coordinator should not proxy the block bytes.
  3. Persist and acknowledge: A storage node validates the block, writes it to local storage, and acknowledges only after the persistence condition chosen by the project is met. Make that condition explicit; receiving bytes in memory is not the same as successfully storing them.
  4. Commit: After the required acknowledgements arrive, the client asks the coordinator to commit. The coordinator records the ordered blocks and their locations and marks the file committed only when its commit policy is satisfied.
  5. Recover an uncertain result: If the client loses its connection after nodes persist data but before it receives confirmation, it should query or retry using the same write ID. The coordinator needs a defined answer for whether that operation committed; orphaned blocks need a cleanup policy.

There is no universal acknowledgement rule for a small implementation. Decide whether commit requires every planned replica or a specified subset, then make the same rule govern client success, metadata state, and recovery. A weaker acknowledgement rule can permit a write to be reported successful while fewer copies exist than the plan requested.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to read a file

  1. The client resolves the path with the coordinator and receives the committed file’s ordered block list, lengths, checksums, and replica locations.
  2. For each block, it selects a listed replica and fetches the bytes directly from that storage node.
  3. The client verifies the returned length and checksum before using the block. If verification or a request fails, it tries another known replica and reports the failure so the coordinator can reconcile its view.
  4. The client assembles verified blocks in the metadata-defined order and returns the file contents.

Checksums and alternate-replica retries are implementation recommendations, not a guarantee supplied by the architecture alone. They make corruption and unavailable-node handling visible instead of silently returning incomplete or invalid data.

Replication, heartbeats, and node recovery

HDFS lets applications choose block size and replication factor per file. Its NameNode tracks DataNodes through heartbeats and block reports: a heartbeat indicates that a node is functioning, while a block report lists the blocks it holds. A Go project can use the same concepts, but must define its own timing, placement, and recovery rules.

  • Heartbeat expires: Decide when a node becomes unavailable for new reads or writes. Expiration is a suspicion based on missed contact, not proof that the machine or its disks are permanently lost.
  • Replica deficit: Compare each committed block’s known healthy locations with its target. Schedule replacement copies only after deciding which source replica is safe to read.
  • Node restarts: Have the node report its local inventory. Reconcile that inventory against coordinator metadata before treating blocks as valid or deleting them; stale metadata and stale disk contents can each lead to incorrect decisions.
  • Stale replicas: Issue deletions explicitly and make them safe to retry. A node should not infer permission to delete data merely because it temporarily cannot contact the coordinator.
  • Duplicate and interrupted work: Make replication, upload, and commit operations idempotent or detect duplicate operation IDs. Specify what remains after partial transfer and how it is eventually cleaned up.

Replica count alone does not guarantee availability. Replicas placed on machines sharing a power source, rack, network path, or other failure domain can fail together. A local learning cluster may not have racks, but its placement policy should still be understood as a reliability and network-use trade-off, not just a number.

Choose the metadata availability you can actually support

Project scope What it buys What it leaves unresolved
Single coordinator with restart persistence A simpler control plane and a manageable first metadata state machine. The coordinator remains a control-plane failure point; its outage limits metadata operations until recovery.
Replicated metadata with consensus A path toward maintaining metadata state across coordinator failures. Requires durable log handling, transport, membership management, snapshots or recovery, and correct integration between committed metadata and block operations.

The etcd Raft Go package provides a replicated-state-machine protocol, not a complete filesystem coordinator. It leaves network transport and disk I/O to its users. A correct integration must persist required entries before sending messages and apply committed log entries to the application state machine. Adding a Raft dependency alone does not make file creation, block placement, or commits safe across failures.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Keep Go concurrency and cancellation deliberate

Decide which goroutine owns each mutable map and state transition. A coordinator can serialize metadata updates through a single owner, or use carefully scoped locks around shared state. Go’s guidance favors communicating through channels for coordination, while recognizing that mutexes can be appropriate for shared state; the useful rule is to choose a clear ownership model rather than mutate coordinator maps from unrelated handlers.

Pass context.Context through request handlers, RPC calls, replication work, and storage operations. Derived contexts can carry deadlines and cancellation, and contexts are safe for simultaneous use by multiple goroutines. Ensure work spawned for an operation exits when its context is canceled and releases files, connections, and other resources.

Disk writes, network calls, and retries can fail independently. Make cancellation, deadlines, retry boundaries, and idempotency part of the interfaces, not afterthoughts in handlers. In particular, a canceled client request does not necessarily mean a remote storage write was canceled before persistence.

Build and validate in stages

  1. Model and local storage: Define file, block, replica, node, and write-state records. Implement a local block-storage interface that can write, read, verify, and list blocks.
  2. One coordinator and one node: Demonstrate a file split across blocks, with the client transferring bytes directly to the node and resolving them through coordinator metadata.
  3. Multiple nodes: Add block reports and heartbeat-based liveness tracking. Test that metadata changes when a node becomes unavailable.
  4. Replication and commit: Implement the chosen acknowledgement policy and test that a file is not marked committed before its requirements are met.
  5. Failure cases: Exercise node loss and restart, duplicate requests, interrupted uploads, disk errors, client disconnects during commit, stale replicas, and coordinator restart.
  6. Metadata replication: Only after single-coordinator persistence and recovery are understandable, add consensus and its transport, durability, and state-machine integration.

Use Go’s go test command and testing package for deterministic unit tests of metadata transitions, checksum validation, retry behavior, and storage operations. Add integration tests that run multiple nodes or processes and inject failures. Do not infer performance, durability, or production readiness from a successful demo: those claims require measurements and failure testing under stated conditions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Know what the first version is not

A working educational system is not automatically a production filesystem. Production scope brings additional requirements around security, access control, operational visibility, upgrades, compatibility, recovery procedures, and validation under realistic failure conditions. Keep the initial claim narrower: a Go implementation that demonstrates namespace metadata, block placement, direct data transfer, and a chosen replication and commit policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.