Apache Kafka for Node.js Developers
Tags: showdev, webdev, tutorial, beginners
Published: 2019-08-11 11:18:28

---
title: Apache Kafka for Node.js Developers
published: true
description: Apache Kafka for Node.js Developers
tags: showdev,webdev,tutorial,beginners
canonical_url : https://cloudnweb.dev/2019/08/apache-kafka-for-node-js-developers/
---
<!-- wp:paragraph -->
<p>In this articles, we will see how to implement apache kafka with node.js. Apache Kafka for Node.js Developers</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Firstly, kafka is a streaming platform which implements the publish/subscriber model.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Further, If you want to Learn  how kafka works under the hood.you can read this article series</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://cloudnweb.dev/2019/04/how-apache-kafka-works-kafka-getting-started-part-1/">Apache Kafka Series - Part 1</a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://cloudnweb.dev/2019/04/kafka-getting-started-kafka-series-part-2/"> Architecture of Kafka Series - Part 2</a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://cloudnweb.dev/2019/05/heres-what-makes-apache-kafka-so-fast-kafka-series-part-3/">Core Concepts of Kafka Series - Part 3</a></p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Kafka and Node.js</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>On the other hand, you can think of why as a node.js developer, i need to learn about Kafka. there is a reason and need for that.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Mainly, we are in the development Era of <strong><a href="https://cloudnweb.dev/2019/04/10-resources-to-make-you-better-at-microservices-in-2019/">Microservices</a></strong>. Most of the Companies prefer to build their applications using Microservices. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you are a Node.js developer, you may also be in a situation where you need to build one. If you do some research on Microservices, you will find lot of resources referring  Kafka along with Microservices.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Reason being, is Many of the UseCases for  Microservices are <strong><a href="https://www.confluent.io/blog/event-sourcing-cqrs-stream-processing-apache-kafka-whats-connection/">Event Sourcing</a></strong></p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Implementating Kafka for Event Sourcing</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>This is one of the  popular usecases where one Microservice talk with another Microservice through Kafka.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1240} -->
<figure class="wp-block-image"><img src="https://cloudnweb.dev/wp-content/uploads/2019/08/event_sourcing.png" alt="" class="wp-image-1240"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Mainly, we will see how to implement the above usecase using Kafka and Node.js</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>User Service - this service handles all the user business logics such as user creation, update and delete.</li><li>Post Service - this service handles all the operations of posts for an user.</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>Event Sourcing comes when we an user is deleted, we need to delete all the posts related to user. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>When Client make an API call, gateway sends the request to respective Microservice.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If the particular service has some data dependencies with other services, it will send the Data to Other services using Kafka(<strong>Event Sourcing</strong>).</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Other Services SubScribes the Kafka Topics and get the data to do the business operations.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Demo</h3>
<!-- /wp:heading -->

<!-- wp:image {"id":1242} -->
<figure class="wp-block-image"><img src="https://cloudnweb.dev/wp-content/uploads/2019/08/Screenshot-2019-08-11-at-4.08.29-PM-1024x530.png" alt="" class="wp-image-1242"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Complete Source Code can be found <a href="https://github.com/ganeshmani/node-eventsourcing">here</a></p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Summary</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Apache Kafka can be used in lot of situations like Event Sourcing,Data Streaming and Message Queue. As a Backend developer, it is always good to know different possibilities to decide the best solution for solving the problem.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>References : </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://microservices.io/patterns/data/event-sourcing.html">EventSourcing - Microservice.io</a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://www.confluent.io/blog/event-sourcing-cqrs-stream-processing-apache-kafka-whats-connection/">Event Sourcing,CQRS - Apache Kafka</a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->