Backend Development 7 min read

Introduction to FastDFS and a Java Integration Example

This article explains the fundamentals of FastDFS, its tracker and storage architecture, the file upload/download workflow, and provides a step‑by‑step Maven‑based Java example—including configuration, dependency setup, and code—to demonstrate how to store and retrieve files in a FastDFS cluster.

Full-Stack Internet Architecture
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Introduction to FastDFS and a Java Integration Example

FastDFS is an open‑source distributed file system written in C, designed for the Internet with features such as redundancy, load balancing, linear scalability, high availability, and high performance, making it easy to build a high‑performance file server cluster for upload and download services.

The architecture consists of two main roles: a Tracker server that performs load balancing and dispatches client requests, and one or more Storage servers that actually store files using the underlying operating system’s file system.

During a file upload, the client first contacts the Tracker server, which selects an appropriate Storage server based on configured strategies; the Storage server then receives the file and returns a file ID containing group name, virtual disk path, two‑level directory, and generated file name. For downloads, the client queries the Tracker to locate the Storage server holding the file and retrieves it directly.

A simple FastDFS deployment includes a Tracker node and one or more Storage nodes, often visualized in architecture diagrams.

To get started, create a Maven project (e.g., fastDFSdemo ) and manually install the FastDFS client JAR into the local Maven repository because it is not available in central repositories:

mvn install:install-file -DgroupId=org.csource.fastdfs -DartifactId=fastdfs -Dversion=1.2 -Dpackaging=jar -Dfile=d:\setup\fastdfs_client_v1.20.jar

Add the dependency to pom.xml :

<dependency>
    <groupId>org.csource.fastdfs</groupId>
    <artifactId>fastdfs</artifactId>
    <version>1.2</version>
</dependency>

Create a configuration file fdfs_client.conf with tracker address, timeouts, log level, and other settings (example content shown in the source).

In Java, initialize the client with the configuration file, obtain a TrackerServer, create a StorageClient, and call upload_file to upload an image. The method returns an array containing the group name and file path, which can be printed to the console.

// Load configuration
ClientGlobal.init("D:/maven_work/fastDFS-demo/src/fdfs_client.conf");
// Create Tracker client and get connection
TrackerClient trackerClient = new TrackerClient();
TrackerServer trackerServer = trackerClient.getConnection();
StorageServer storageServer = null;
StorageClient storageClient = new StorageClient(trackerServer, storageServer);
// Upload file
String[] result = storageClient.upload_file("D:/pic/benchi.jpg", "jpg", null);
for (String s : result) {
    System.out.println(s);
}

The console output shows the group and file path, e.g., group1 and M00/00/00/wKgZhV4r9uSAZvkZAAaZOWtmGtU020.jpg . Access the file via a URL such as http://192.168.25.133/group1/M00/00/00/wKgZhV4r9uSAZvkZAAaZOWtmGtU020.jpg .

backendJavamavendistributed file systemfastdfsfile storage
Full-Stack Internet Architecture
Written by

Full-Stack Internet Architecture

Introducing full-stack Internet architecture technologies centered on Java

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.