The Innovation Driving Our 8 Consecutive Year on the Inc. 5000 List

Apache Kafka Use Cases and How to Run It in 5 Easy Steps

Apache Kafka Use Cases and How to Run It in 5 Easy Steps

In a series of posts we are going to review different variances of platforms, frameworks, and libraries under the umbrella of Java. For this post, we are going to cover a basic view of Apache Kafka and why I feel that it is a better optimized platform than Apache Tomcat.

What is Apache Kafka? It is a streaming platform with three, key components:

  1. – Publish and subscribe to streams of records, similar to a message queue or enterprise messaging system
  2. – Store streams of records in a fault-tolerant durable way
  3. – Process stream of records as they occur

Kafka is used for real-time streams of data used to collect big data, to do real-time analysis or both. Kafka is used with in-memory microservices to provide durability, to feed events to cEP (complex event streaming systems), and IoT style automation systems.

Since Kafka is fast, scalable durable and fault tolerant publish/subscribe messaging system, it is used in cases where JMS, RabbitMQ and AmQP may not be considered due volume and responsiveness

  • – Stream processing
  • – Website activity tracking
  • – Metrics collections and monitoring
  • – Log aggregations
  • – Real-time analytics
  • – Ingesting data into Hadoop
  • – Replay messages
  • – Error recovery
  • – Guaranteed distributed commit log for in-memory computing

Also, Kafka has four, core APIs:

  • – The Consumer API allows and application to subscribe to one or more topics and process the stream of records produced to them
  • – The Streams API allows an application to act as a stream processor, consuming an input stream from on or more topics and producing an output stream to one or more output topics, effectively transforming the input streams to output streams
  • – The Connector API allows building and running reusable producers or consumers that connect Kafka topics to existing applications or data systems. For example, a connector to a relational database might capture every change to a table.

The “publisher” generates data (a message) but it doesn’t have any reference to the subscriber, the message is not sent directly, instead of that the publisher can set the message in a certain “topic”. The receptor can subscribe it self in a certain topic and receive messages from this. Multiple receptors can be subscribed in a topic to get the information.

This diagram should provide for an easier understanding:

  • Next Generationused by Netflix, Microsoft, Banks, etc.
  • High Performanceable to work with low latency because it comes from an OS kernel
  • DistributedCan be divided into several nodes inside a cluster
  • Horizontal ScalableSeveral nodes can be added in a few minutes
  • PersistenceThe messages are stored in a file system which can be replicated between the nodes in the cluster
  • Fault TolerantAll the nodes have a replica from other nodes. In the case that a node would fail, another would take its place
  • SecuritySupport for SSL, SASL, GSSAPI. Can set encrypted connections for producers, consumers, brokers, & clients.
  • Java Virtual Machine
  • KSQL (similar to SQL) to work with streams
  • ZookeeperSoftware that provides a high performance coordination for distributed applications. This element should be the first one to start if the user wants a distributed coordination
  • BrokerIt’s a Kafka instance or server. Mediator in the communication for the message delivery
  • ClusterA group of Brokers
  • MessageA data unit that works with Kafka, an example could be an array of bytes
  • SchemaAn optional structure applied on the messages. Some examples: JSON, XML, Apache Avro
  • TopicCategory where the messages can classified in Kafka. A stream of messages with a name
  • PartitionAn ordered message sequence
  • Offset – A unique identifier based in its place inside a partition. The consumer position in the topic or partition

The prerequisite is to install JRE

Step 1: Download Apache Kafka

To run Kafka, first we need to download the binaries from the site:

Step 2: Start the Server

Kafka uses ZooKeeper so you need to first start a ZooKeeper server if you don’t already have one. You can use the convenience script packaged with kafka to get a quick-and-dirty single-node ZooKeeper instance.

For Windows:

binwindowszookeeper-server-start.bat config/

For Linux: config/

Now we start the server:

For windows:

binwindowskafka-server-start.bat config/

For Linux: config/

Step 3: Create a Topic

Creating a topic named “test” with a single partition and only one replica.

For Windows:

bin/windows/kafka-topics.bat –create –bootstrap-server localhost:9092 –replication-factor 1 –partitions 1 –topic test

For Linux:

bin/ –create –bootstrap-server localhost:9092 –replication-factor 1 –partitions 1 –topic test

To list the topics:

For Windows:

bin/windows/kafka-topics.bat –list –bootstrap-server localhost:9092

For Linux:

bin/ –list –bootstrap-server localhost:9092
Step 4: Sending the Messages

Run the producer and then type a few messages into the console to send to the server.

For Windows:

bin/windows/kafka-console-producer.bat –broker-list localhost:9092 –topic test

For Linux:

bin/ –broker-list localhost:9092 –topic test

Step 5: Start a Consumer

Kafka also has a command line consumer that will dump out messages to standard output.

For Windows:

bin/windows/kafka-console-consumer.bat –bootstrap-server localhost:9092 –topic test –from-beginning

For Linux:

bin/ –bootstrap-server localhost:9092 –topic test –from-beginning


Thanks for taking the time to review the basics of Apache Kafka, how it works and some simple examples of a message queue system. Be prepared for our next post, where we discuss how to use Kafka Streams to process data.

Stay Tuned!


Víctor Madrid, Aprendiendo Apache Kafka, July 2019, from

Víctor Madrid, Aprendiendo Apache Kafka Parte 2, July 2019, from

Cloudurable, What is Kafka, July 2019, from

Apache Kafka, Introduction, July 2019, from

Apache Kafka, Quick Start, July 2019, from


Ready to dive in?
Start with Unosquare today.

Unosquare is a full-service, international software development agency. Through our centers of excellence we recruit, train and professionally manage talent to ensure expertise from discovery to delivery.