Skip to content
Sdelux
Back to Code
Code

Peer-to-Peer Distributed File System

A network-distributed file system based on a P2P ring architecture.

View codePythonAWSDockerDistributed SystemsSQL

Built for the Distributed Systems course at EAFIT University and deployed on AWS.

Project Objective

DFSha is a distributed file system (DFS) that allows large files to be stored and retrieved by distributing them across multiple nodes. Its goal is to distribute both write and read operations across a set of nodes, enabling the system to scale in terms of file size and request volume, tolerate node failures without losing data access, and provide clients with a hierarchical file system abstraction similar to that of a Linux system.

The system follows a P2P architecture, where the service is provided by a set of equal peers organized into a logical ring over the network, without a central coordination or metadata node.

Service Description

The service provides clients with the illusion of a single, hierarchical file system, even though the data is fragmented and replicated across the entire ring of peers. Clients do not know—and do not need to know—how files are split or where each fragment is stored. This is precisely the transparency property the system aims to achieve.

Architecture

The system is organized as a consistent hashing ring in which each peer acts both as a client-facing server and as an equal participant in the network. There is no hierarchy: all peers run the same code and perform the same role.

Components

  • CLI Client: User interface. Presents a standard hierarchical DFS and does not expose fragments or replicas.
  • gRPC Service: Translates network calls into operations on the coordinator (external interface) and exposes peer-to-peer primitives (internal interface).
  • Coordinator: Business logic responsible for splitting files into fragments, determining their locations, replicating them, assembling and disassembling the directory tree, and rebalancing data when membership changes.
  • Hashing (Ring): Determines which peer(s) own a given key for partitioning and replication.
  • Membership (Gossip): Maintains a view of which peers are alive and propagates this information throughout the ring.
  • Local Storage: Key-value persistence for each peer.

Protocols and APIs

All system communication uses gRPC over the network. Two independent communication planes are defined, each with its own service.

Client–Peer Plane

This is the external interface exposed by a peer to clients. It is stateless, meaning any peer can handle any request.

  • Ls: Lists the contents of a directory.
  • Mkdir: Creates a directory.
  • Rmdir: Removes an empty directory.
  • Rm: Deletes a file.
  • Send: Uploads a file as a stream of byte chunks.
  • Receive: Downloads a file as a stream of fragments.

Peer–Peer Plane

This is the internal interface exposed by a peer to other peers. It enables data replication and retrieval between nodes and maintains ring membership.

  • HealthCheck: Checks whether a peer is alive and exchanges the list of known peers, including their weights.
  • StoreBlob: Stores a blob (fragment, metadata, or index) under a key.
  • GetBlob: Retrieves a blob by its key.
  • DeleteBlob: Deletes a blob by its key.

Dynamic Membership Through Gossip

There is no central peer registry. Each peer starts with knowledge of at least one seed address and periodically performs a HealthCheck on the peers it knows. In each response, both peers exchange their lists of known peers (anti-entropy), allowing membership information to propagate throughout the ring. Along with each address, gossip propagates the weight of each peer, which is used to determine the weighted distribution of fragments.

Algorithms and Techniques Used

  • Consistent Hashing: Distributes keys across the nodes in a network.
  • Weighted Virtual Nodes: Distributes the workload according to each node’s capacity.
  • Replica Selection Algorithm: Selects the primary node and the nodes where copies will be stored.
  • Streaming Chunking: Splits large files into fragments as they are received.
  • Incremental Hashing: Calculates a content fingerprint to verify file integrity.
  • Data Replication: Stores copies of data across different nodes.
  • Rebalancing with Hinted Handoff: Redistributes data when nodes join or leave, preventing data loss during migration.