Kafka được dùng rộng rãi cho log aggregation, event sourcing, CDC, và microservices communication nhờ khả năng lưu trữ và replay message.
Các use case phổ biến của Kafka trong production:
- Log aggregation: tập hợp log từ nhiều service vào một nơi, sau đó forward sang Elasticsearch hoặc S3 để phân tích.
- Event sourcing: lưu tất cả sự kiện (thay vì chỉ state hiện tại) để rebuild state bất kỳ lúc nào.
- Real-time analytics: stream data từ user activity vào Kafka, xử lý với Kafka Streams hoặc Flink để cập nhật dashboard real-time.
- Microservices communication: thay vì gọi API trực tiếp (tight coupling), các service publish event và service khác subscribe — giảm coupling và tăng resilience.
- Change Data Capture (CDC): dùng Debezium để capture mọi thay đổi từ database, sync sang data warehouse hoặc invalidate cache.
- Fraud detection: stream giao dịch tài chính qua Kafka, dùng ML model để detect bất thường trong real-time.
Kafka is widely used for log aggregation, event sourcing, CDC, and microservices communication thanks to its ability to store and replay messages.
Most common real-world use cases for Kafka:
- Log aggregation: collecting logs from many services into one place, then forwarding to Elasticsearch or S3 for analysis.
- Event sourcing: storing every event (rather than just current state) so state can be rebuilt at any point in time.
- Real-time analytics: streaming user activity data into Kafka, processing with Kafka Streams or Flink to update dashboards in real time.
- Microservices communication: instead of direct API calls (tight coupling), services publish events and others subscribe — reducing coupling and improving resilience.
- Change Data Capture (CDC): using Debezium to capture all database changes, syncing to a data warehouse or invalidating caches.
- Fraud detection: streaming financial transactions through Kafka and applying ML models to detect anomalies in real time.