Use hdfs as backend storage for kafka, is it doable?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Apache Kafka and Hadoop Distributed File System (HDFS) are two critical components in the landscape of big data tools. Both serve ultra-high-scale data workloads but have very different characteristics and serve different purposes within a data architecture. To bring Kafka's capabilities as a high-throughput messaging system together with the strong data storage features of HDFS, it's useful to explore whether HDFS can be utilized as a backend storage for Kafka.
Understanding Kafka Storage
Apache Kafka typically stores its logs (messages) on local disk storage. Kafka ensures durability and high performance by replicating these logs across different brokers in a Kafka cluster. Moreover, synchronizing this log content between different cluster nodes allows Kafka to recover quickly in case of a node failure.
HDFS Overview
HDFS, part of the Apache Hadoop ecosystem, is a distributed file system designed to store very large data sets reliably, and to stream those data sets at high bandwidth to user applications. It breaks down data into blocks and distributes them across a cluster of machines. It offers fault tolerance by replicating each piece of data multiple times across different nodes.
Can HDFS Serve as Kafka's Storage Backend?
The integration of Kafka with HDFS is not straightforward. Officially, Kafka does not support using HDFS as a log storage medium. Kafka's high-performance message delivery guarantees are closely tied to the characteristics of local file systems, specifically:
- Low latency access and append operations: HDFS, being a distributed system, has higher latencies due to network communications and other overheads.
- Horizontal scalability: Kafka is designed to horizontally scale on commodity hardware using local storage which simplifies its architecture and optimizes its performance.
However, integrating Kafka with HDFS can be considered in a different architectural framework—where HDFS is not directly used for log storage, but rather for log data archiving or as a part of a data processing pipeline.
Kafka Connect HDFS
An alternative approach for combining the power of both Kafka and HDFS is through the use of Kafka Connect HDFS. Kafka Connect is a tool for scalably and reliably streaming data between Apache Kafka and other data systems such as HDFS. It can be used to:
- Export data from Kafka topics to HDFS.
- Ensure that the data is available in HDFS for large scale processing and analytics with tools like Apache Hive or Apache Spark.
This integration does not use HDFS as backend storage per se, but rather as a downstream system for data storage and analysis.
Key Operations and Features:
- Automated data balancing: Kafka Connect can automatically manage the distribution of data across the cluster.
- Configuration-driven management: Users can manage and configure connectors via Kafka's centralized configuration service.
- Scale-out architecture: Kafka Connect scales linearly with data volume and velocity.
Summary Table
| Feature | Kafka Native Storage | HDFS | Kafka Connect with HDFS |
| Storage Location | Local Disks | Distributed Across Cluster | Local Disks for Logs; Distributed for snapshots/archives |
| Latency | Low | High | Low for Kafka Operations; High for HDFS writes |
| Scalability | High Horizontally for Processing | High Horizontally for Storage | High for Both Processing and Storage |
| Fault Tolerance | High (Data Replication) | High (Data Replication) | High (Combined Features) |
| Use Case | Real-time Messaging | Large Scale Batch Processing | Real-time + Batch Processing | Data Enrichment | Archival |
Conclusion
Using HDFS directly as a backend storage for Kafka logs is not supported and is not feasible given their inherent architectural differences targeting different aspects of data handling. However, integrating Kafka with HDFS via Kafka Connect represents a viable and efficient method to leverage the strengths of both systems—facilitating a robust, scalable, and flexible data infrastructure that supports both real-time and batch processing workflows. This approach offers businesses a powerful toolkit for comprehensive data analysis and decision making.

