Kafka Streams with lookup data on HDFS
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Apache Kafka Streams is a client library for building applications and microservices, where the input and output data are stored in Kafka clusters. Kafka Streams combines the simplicity of writing and deploying standard Java and Scala applications on the client side with the benefits of Kafka's server-side cluster technology.
What is Kafka Streams?
Kafka Streams is part of the Apache Kafka project. It provides a way to process streams of data in real-time. With simple stream processing primitives like filter, map, join, and aggregate, Kafka Streams allows for complex processing topologies. Developers can build applications using only Kafka Streams APIs, and the deployed applications will then run on regular host hardware, or across multiple containers in orchestrated systems.
Handling Lookup Data from HDFS
Problem Statement
While Kafka Streams is excellent for real-time data processing, there are scenarios in which external lookup data is necessary for enrichment or validation of the streams. A common practice involves storing this static or rarely changing data on distributed file systems like HDFS (Hadoop Distributed File System).
Solution
Kafka Streams doesn't directly interact with HDFS. However, you can integrate Kafka Streams with HDFS data via mechanisms such as loading data into memory, reading data into a Kafka topic, or using an external database that syncs with HDFS.
Implementation Example
Here’s a simple example scenario: enriching streaming data with reference data stored in HDFS:
- HDFS Setup: Let's assume you have user information stored in HDFS that is periodically updated.
- Data Loading: You export this data into a Kafka topic. This can be done using tools like Apache Flume or Apache NiFi.
- Stream Processing Application: In your Kafka Streams application, you'd keep an in-memory store (e.g., KeyValueStore) of the user data that gets updated by consuming the Kafka topic where the HDFS exported data is streamed.
- Consumption and Output: The enriched data stream in the Kafka Streams application can then be used for real-time analytics or piped out to another Kafka topic, external systems, or back to HDFS.
Considerations and Best Practices
- Memory Management: Be aware of the memory footprint, especially if the reference data is large.
- Update Frequency: Determine how frequently the lookup data changes and should be updated/refreshed in your Kafka application.
- Fault Tolerance: Implement proper error handling and recovery mechanisms, especially concerning the synchronization between HDFS and your Kafka Streams application.
Summary Table
| Feature | Description |
| Real-time Processing | Processes data in real-time using simple and complex topologies. |
| Integration with HDFS | HDFS can be integrated indirectly via intermediate Kafka topics. |
| State Management | Handles states within the application through various state stores. |
| Scalability | Easily scalable to handle large streams of data by adding more instances. |
| Fault Tolerance | Built-in mechanisms to manage failures and ensure data is processed correctly. |
Conclusion
Kafka Streams, while primarily targeted at real-time data processing directly from Kafka topics, offers flexibility to integrate with various external systems including HDFS. Utilizing Kafka as a bridge, one can manage and process large datasets efficiently, enrich streams with external data, and leverage the robust streaming capabilities of Kafka Streams.
Related reading
- Kafka Streams with Spring Boot
- Kafka streams.allMetadata() method returns empty list
- Kafka Structured Streaming KafkaSourceProvider could not be instantiated
- Kafka suddenly reset the consumer Offset
- Kafka There is no leader for this topic-partition as we are in the middle of a leadership election
- Kafka topic alias
- Kafka to Elasticsearch, HDFS with Logstash or Kafka Streams/Connect
- Kafka to Pandas dataframe without Spark

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack 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.