Overview

5 Kafka in real-world use cases

This chapter turns Kafka’s fundamentals into practical guidance for real-world decisions. It maps high-impact scenarios—notifications, external data integration, real-time analytics, and log aggregation—to Kafka’s strengths, clarifies the guarantees you gain and the operational costs you incur, and outlines antipatterns and edge cases where another tool may fit better. Along the way, it equips architects with a pragmatic checklist and mental model for evaluating Kafka’s applicability, while surveying viable alternatives such as RabbitMQ, Apache Pulsar, and managed cloud services.

In event-driven microservices, producers publish keyed events to preserve per-entity ordering while consumers maintain local read models; topic compaction, extended retention, and tiered storage support different durability and rebuild strategies, but Kafka remains a log, not a database. Data integration leans on snapshot replication and change data capture, with Kafka Connect and its connector ecosystem enabling low-code pipelines that can be enriched downstream by stream processing—balanced against added operational overhead, security concerns around raw data exposure, and fragility under schema drift. For centralized logging, Kafka decouples producers from backends like Elasticsearch, buffering spikes and improving durability and throughput; this adds cost and often warrants a separate cluster, and may be overkill for small estates. Real-time processing with frameworks such as Kafka Streams delivers low-latency insights and microservice-friendly scaling, but introduces a learning curve, state management complexity, operational sprawl, and uneven tooling.

The chapter also delineates where Kafka may not be ideal: it favors publish-subscribe over point-to-point semantics, partitions limit global ordering, brokers don’t perform content-based routing or schema validation, access is sequential (not content-indexed), and large messages require workarounds like externalized payloads. While Kafka excels at high-throughput, fault-tolerant streaming, batch-centric workflows and strict per-message transactions can be awkward. Alternatives fill different niches: RabbitMQ offers queues, request-reply, and smart routing (with a streaming add-on); Pulsar separates stateless brokers from BookKeeper storage and adds multitenancy and geo-replication; cloud services provide managed elasticity with differing semantics. Choosing among them hinges on throughput and latency needs, routing complexity, consistency requirements, ecosystem maturity, team expertise, and whether real-time or batch processing truly delivers the most value.

Flow diagram illustrating how ProfileService sends notifications about profile changes to Customer360Service through Kafka
Using compacted topics in Kafka: you always retain the latest version of each event, allowing Kafka to act as a source of truth
Setting up Kafka Connect for data replication involves using PostgreSQL and MongoDB as source systems. Source connectors are responsible for pulling data from these systems and inserting it into Kafka topics. In turn, sink connectors pull the data from Kafka and insert it into the target systems. In this setup, both sink connectors consume data from the same topics, with one inserting the data into an MS SQL database and the other into Amazon S3.
A workflow for source connectors
A workflow for sink connectors
Conceptual flow for log data collection: Log data is sent from the application to Kafka for processing, it’s then indexed in Elasticsearch, and it’s finally visualized in Kibana.
Sending log data via Kafka to Elasticsearch
The fraud detection application acts as a producer and a consumer for Kafka topics. It reads messages from the Transactions topic, processes them, and sends the output results to the Fraudulent Transactions topic.
Passing messages with references to content stored externally
Time-based batch load to the data warehouse: the consumer buffers records and, at fixed intervals, bulk-loads a batch to the data warehouse (rather than per-message processing).
Unexpected ordering. Earlier-timestamped messages can arrive later because of network delays.
RabbitMQ architecture
Apache Pulsar architecture

Summary

  • Microservices that communicate through events can use Kafka as an underlying integration platform, providing decoupled communication between services, improving scalability and fault tolerance. Kafka offers an efficient and scalable solution for integrating microservices in distributed architectures.
  • Kafka’s ability to process events with high throughput makes it ideal for collecting logs and metrics, as Kafka can handle vast amounts of data at a high rate.
  • Data replication can be implemented using Kafka Connect, a key component of the Kafka ecosystem. Kafka Connect provides a flexible and scalable way to implement data replication without extensive custom development.
  • Various frameworks tightly integrated with Kafka allow building applications that process data in real time, empowering businesses to react to data as it is generated, enabling advanced real-time use cases.
  • RabbitMQ and Apache Pulsar are messaging platforms that compete with Kafka, each serving its own niche. RabbitMQ excels in low-latency, transactional messaging, while Pulsar’s architecture with stateless brokers and separate storage makes it more scalable for certain use cases. The choice between Kafka, RabbitMQ, and Pulsar depends on non-functional requirements such as scalability, real-time processing, and transactional guarantees.
  • Kafka excels at processing small messages at a high rate with minimal latency, making it a top choice for real-time event-driven systems. Examples include clickstream analytics, fraud scoring on card transactions, IoT telemetry ingestion, and real-time operational alerting.
  • Kafka may not be the best choice for use cases requiring strict ordering, batch transfers, or random data access (e.g., a single-sequence financial ledger or nightly bulk file/table transfers for ETL).

FAQ

What real-world use cases are a great fit for Kafka?Kafka shines in event-driven microservices, external data integration (especially CDC), real-time stream processing and analytics, and centralized log/metrics aggregation. It also works well for fan-out notifications and as a durable backbone to decouple producers and many independent consumers. Its high throughput and replayable retention make it ideal when multiple systems need the same data at different times.
When is Kafka not the best choice?Prefer alternatives when you need synchronous request-response, strict cross-service transactions with immediate outcomes, or simple, low-volume systems where Kafka’s operational overhead is unnecessary. Kafka is a poor fit for broker-enforced point-to-point semantics, content-based routing or validation at the broker, random access by message content, global ordering across an entire topic, very large messages, and workflows designed purely for batch ETL.
How should I choose between Kafka and RabbitMQ?Kafka favors publish-subscribe with “smart endpoints/dumb pipes,” high throughput, durable retention, and replay. RabbitMQ excels at “dumb endpoints/smart pipes” with exchanges that support complex routing, queues for point-to-point, and request-reply patterns. Pick Kafka for high-throughput event streams and fan-out; pick RabbitMQ when you need queue semantics, sophisticated routing, or simple synchronous patterns. RabbitMQ Streams narrows the gap by adding log-like streaming.
How does Apache Pulsar compare to Kafka?Pulsar separates stateless brokers from storage (Apache BookKeeper), enabling independent scaling and fast recovery. It offers built-in geo-replication, multitenancy, dead-letter topics, non-persistent messaging, and queue-like subscriptions. Kafka has the larger ecosystem, tooling, and community. Pulsar can expose a Kafka protocol handler so Kafka clients can talk to Pulsar without code changes.
How can microservices use Kafka as a source of truth for state?Use compacted topics to retain only the latest value per key, allowing services to rebuild state from Kafka and keep only in-memory or lightweight stores. Alternatively, set delete-retention to “effectively forever” and/or use tiered storage to keep full history more cheaply. Plan for tradeoffs: Kafka is not a database (no indexes, joins, SQL, or referential integrity) and rebuilding state from an event log adds latency.
What is Kafka Connect and when should I use it for data integration?Kafka Connect is a no-code/low-code framework for moving data in and out of Kafka via pluggable connectors. Use snapshot-based connectors (e.g., JDBC) or CDC via Debezium to stream inserts/updates/deletes. Pros: large connector marketplace, scalable, uniform pipelines. Cons: some commercial licenses/costs, schema-change fragility, and raw data exposure risks. Alternatives include custom producers/consumers, DB replication tools (e.g., GoldenGate), and traditional ETL platforms.
How do I build a centralized logging pipeline with Kafka, and what are the tradeoffs?Common pattern: apps log via frameworks or agents (e.g., Fluentd/Fluent Bit) → Kafka buffers and fans out → Kafka Connect indexes logs into Elasticsearch/OpenSearch → dashboards in Kibana. Benefits: decoupling, durability, high throughput, and backpressure buffering. Tradeoffs: resource-intensive, different nonfunctional needs than business streams—often warrant a separate Kafka cluster. Alternatives include syslog, Logstash, direct-to-Elasticsearch, or SaaS platforms like Datadog/New Relic.
What implementation challenges should I expect with event-driven systems on Kafka?Managing delivery guarantees under retention constraints, immutable messages with no broker-side validation (requiring strong data contracts), and schema evolution/versioning are key challenges. Distributed, asynchronous flows complicate tracing and debugging, especially timing and ordering issues. You’ll need solid observability, error handling, and governance around schemas and topic lifecycles.
How do partitions and ordering affect system design?Kafka guarantees ordering only within a partition; use a stable key (e.g., customer ID) to maintain per-entity order. Global ordering requires tradeoffs: a single partition (limits throughput), adding sequence numbers, or consumer-side reordering (e.g., by timestamp) with careful handling of late events. Multiple producers and network delays can cause unexpected interleaving at the broker, so plan for reordering logic where strict order matters.
How should I handle large messages and batch workflows with Kafka?Prefer storing large payloads in external object storage and send only a reference through Kafka; alternatively split payloads into parts, ensuring they land on the same partition. As a last resort, raise size limits across brokers, producers, and consumers (with resource tradeoffs). Batch processing is possible but awkward: you must aggregate across partitions, define batch boundaries despite late events, and handle partial failures. When batch is primary, consider dedicated batch/ETL tools or warehouse loaders.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Kafka for Architects ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Kafka for Architects ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Kafka for Architects ebook for free