How javadbahoosh/spark-streaming-multi-language-docker works
Major Components
• Docker Compose Infrastructure – Represent the orchestration layer that builds and runs all Docker images (containers).
• Kafka – A central messaging broker system that is used to receive messages from the producer.
• Spark Streaming Consumers – Separate containers for each language implementation:
○ Scala Consumer (with its own Docker image and build configuration via SBT).
○ Python Consumer (with its Docker image and consumer.py).
○ Java Consumer (with its Docker image, Maven configuration using pom.xml, and KafkaConsumer.java).
• Producer – A dedicated container (written in Python, as seen in the producer folder) that pushes messages to the Kafka topic.
• Redis – The data store that aggregates the metrics (e.g., total messages and sums). Also note the run.sh script which monitors specific Redis keys for each language.
Relationships and Data Flow
• The Producer sends messages to a Kafka topic.
• The Kafka broker serves as the central hub that each Spark Streaming consumer (across Scala, Python, and Java) subscribes to.
• Each consumer processes the stream data and then updates corresponding keys in Redis:
• scala_total_messages and scala_total_sum
• python_total_messages and python_total_sum
• java_total_messages and java_total_sum
• Additionally, the run.sh script periodically monitors these Redis keys to track performance or status.
• Docker Compose ties these containers together by orchestrating the startup order, networking, and shared environment.
Architectural Patterns and Design Principles
• Multi-language microservices: Each consumer is implemented in a different programming language but is designed in a similar fashion, exposing an easily comparable pattern.
• Containerized deployment: All components are self-contained in Docker images, emphasizing isolation, ease of scaling, and consistency across environments.
• Event-driven data processing: Leveraging Kafka for message transport ensures that producers and consumers are decoupled.
• Monitoring and Aggregation: Redis acts as a centralized place to capture and monitor key metrics for each consumer.
Relevant Technologies
• Docker & Docker Compose for container orchestration.
• Kafka as the messaging system.
• Spark Streaming (as a concept, even if the code is a lightweight boilerplate example) for consuming and processing messages.
• Redis for tracking processed metrics.
• Build tools and languages:
○ Scala (sbt for Scala projects)
○ Python (producer and consumer implementations)
○ Java (Maven with pom.xml)