Skip to content

Latest commit

 

History

History
35 lines (18 loc) · 3.91 KB

File metadata and controls

35 lines (18 loc) · 3.91 KB

Kafka Usage in this System: Architecture and Best Practices

Kafka Core Usage

  • Message Delivery and Task Assignment: Kafka acts as the backbone for communication between the master_node and multiple worker_nodes. It ensures distributed task management by delivering tasks to worker nodes and receiving processed results.

  • Decoupling Services: Kafka allows master_node and worker_nodes to operate independently. If any node becomes temporarily unavailable, Kafka retains messages and tasks, ensuring no data or task is lost.

  • Log Streaming to Frontend via Server-Sent Events (SSE): Kafka facilitates real-time log streaming from worker nodes to the frontend. The logs generated during model training are continuously sent through Kafka topics and exposed to the frontend using Data Streams with SSE. This ensures users receive up-to-the-moment feedback on the progress of training.

Design Considerations

  • High Availability and Fault Tolerance: Kafka partitions data across multiple brokers, with replication to prevent data loss in case of broker failure. This guarantees system stability.

  • Scalability through Consumer Groups: Kafka’s consumer groups allow multiple worker_nodes to simultaneously process tasks, enhancing concurrency. Kafka automatically reassigns partitions to consumers within the group, maximizing throughput.

  • Asynchronous Task Submission and Reporting: Kafka enables non-blocking submission of tasks from the master_node and asynchronous reporting of results back to the frontend. This architecture minimizes delays and avoids blocking the main execution thread.

Best Practices in this System

  • Multiple Partitions for Increased Parallelism: Each topic is configured with multiple partitions (e.g., 3 partitions for the task topic) to support parallel processing. Multiple worker_nodes can simultaneously process different partitions, enhancing system throughput and reducing processing time.

  • Replication for Reliability and Fault Tolerance: Topics like task and training_log are configured with replication factors of 2 or 3. This ensures data redundancy—if one broker goes down, other brokers still maintain a copy of the partition, ensuring no loss of messages.

  • Automatic Offset Management to Prevent Message Loss: Consumers use auto.offset.reset='earliest' and automatic or manual offset commits to track the last consumed message. This prevents duplicate consumption and ensures no messages are missed during consumer restarts or failures.

  • Asynchronous Task Execution with SSE for Real-time Feedback : Worker nodes send logs back to Kafka during training, which are streamed to the frontend via Server-Sent Events (SSE). Kafka ensures ordered delivery of logs through the training_log topic. SSE provides low-latency log updates to the frontend, allowing users to monitor training in real-time.

  • Graceful Error Handling and Resource Management: Each training session ensures garbage collection (gc.collect()) and session cleanup (K.clear_session()) to release memory. Prevents memory leaks during long-running training sessions, maintaining application stability over time.

  • Callback Mechanism for Fine-grained Monitoring of Model Training: Custom KafkaCallback hooks into the end of each epoch to report intermediate results (accuracy, loss) back to Kafka. Users get real-time updates on the training progress, improving transparency and user experience.

Conclusion

This architecture leverages Kafka for scalable, reliable, and asynchronous task management. Kafka’s data streaming capabilities combined with Server-Sent Events (SSE) ensure that users receive real-time feedback on training processes, while replication and consumer groups guarantee high availability. The system design follows distributed computing best practices, providing both performance and resilience, ensuring that no message or task is lost and that users stay informed throughout the process.