Flume
HTTP
HDFS
Kafka
Data Streaming

Flume use case reading from HTTP and push to HDFS via Kafka

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Apache Flume is a distributed, reliable, and available system for efficiently collecting, aggregating, and moving large volumes of log data. Its primary use is to gather log data from various sources and send it to a centralized data store. The integration of Apache Flume with Apache Kafka and HDFS (Hadoop Distributed File System) broadens its usability, enabling robust data ingestion pipelines that are scalable and fault-tolerant. In this article, we discuss a specific use case: reading data from an HTTP source and pushing it to HDFS via Kafka, detailing how each component fits into the architecture and provides practical configuration snippets.

Overview of Components

Apache Flume

Flume's architecture is straightforward, consisting of sources, channels, and sinks. In our use case:

  • Source: HTTP Source — collects data sent over HTTP.
  • Sink: Kafka Sink — pushes data to a Kafka topic.

Apache Kafka

A distributed streaming platform that can publish, subscribe to, stream, store, and process streams of records in real time. In this scenario, it acts as a message buffer and transportation layer between Flume and HDFS.

HDFS

A distributed file system designed to store very large datasets reliably, and to stream those data sets at high bandwidth to user applications. In this case, it acts as the final destination for the data.

Architecture Flow

  1. Data Ingestion: Data is sent to Flume via an HTTP POST request.
  2. Flume Configuration: The HTTP Source receives this data and passes it onto a channel.
  3. Data Transfer via Kafka: Data in the channel is consumed by a Kafka Sink, which pushes it to a Kafka topic.
  4. Data Consumption: A separate Flume agent with a Kafka Source and an HDFS Sink reads from the Kafka topic and writes into HDFS.

Configuration Examples

1. Flume Configuration for HTTP Source to Kafka Sink

conf
1# Define source, channel, and sink
2a1.sources = r1
3a1.channels = c1
4a1.sinks = k1
5
6# Configure the source
7a1.sources.r1.type = http
8a1.sources.r1.port = 5140
9a1.sources.r1.bind = 0.0.0.0
10
11# Configure the channel
12a1.channels.c1.type = memory
13a1.channels.c1.capacity = 1000
14a1.channels.c1.transactionCapacity = 100
15
16# Configure the sink
17a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink
18a1.sinks.k1.brokerList = localhost:9092
19a1.sinks.k1.topic = http_to_hdfs
20
21# Bind the source and sink to the channel
22a1.sources.r1.channels = c1
23a1.sinks.k1.channel = c1

2. Flume Configuration for Kafka Source to HDFS Sink

conf
1# Define source, channel, and sink
2a2.sources = r2
3a2.channels = c2
4a2.sinks = k2
5
6# Configure the source
7a2.sources.r2.type = org.apache.flume.source.kafka.KafkaSource
8a2.sources.r2.zookeeperConnect = localhost:2181
9a2.sources.r2.topic = http_to_hdfs
10
11# Configure the channel
12a2.channels.c2.type = memory
13a2.channels.c2.capacity = 1000
14a2.channels.c2.transactionCapacity = 100
15
16# Configure the sink
17a2.sinks.k2.type = hdfs
18a2.sinks.k2.hdfs.path = hdfs://localhost/user/flume/data/
19a2.sinks.k2.hdfs.fileType = DataStream
20
21# Bind the source and sink to the channel
22a2.sources.r2.channels = c2
23a2.sinks.k2.channel = c2

Key Points Summary

ComponentRoleConfiguration KeyRemarks
HTTP SourceCollects Datatype: http, port: 5140, bind: 0.0.0.0Listens for incoming data over HTTP.
Kafka SinkPushes to Kafkatype: kafka, brokerList, topicEnsures reliable delivery to Kafka topic.
Kafka SourceReads from Kafkatype: kafka, zookeeperConnect, topicRetrieves data from Kafka for processing or storage.
HDFS SinkWrites to HDFStype: hdfs, hdfs.path, hdfs.fileTypeStores data into HDFS. Configurable to handle data formats and replication factors.

Additional Considerations

  • Scalability: Both Kafka and Flume are horizontally scalable. You can increase the number of Flume agents and Kafka brokers based on throughput requirements.
  • Fault Tolerance: Kafka provides built-in fault tolerance through replication. Ensure that Flume's channel is configured to handle failures (e.g., by using a file channel instead of memory for higher reliability).
  • Monitoring and Management: Utilize tools like Apache NiFi or commercial solutions for more intricate setups or when additional features like visual management, enhanced security, and fine-grained control are necessary.

Conclusion

Integrating Flume with Kafka and HDFS provides a potent solution for robust data pipelines capable of handling high throughput and providing reliability, making it suitable for scenarios where data loss is not acceptable. This setup is commonly used in logging and event processing in large-scale systems, where resilience, scalability, and data integrity are paramount.


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.