Apache Kafka for Node.js Developers

In this articles, we will see how to implement apache kafka with node.js. Apache Kafka for Node.js Developers

Firstly, kafka is a streaming platform which implements the publish/subscriber model.

Further, If you want to Learn how kafka works under the hood.you can read this article series

Apache Kafka Series - Part 1

Architecture of Kafka Series - Part 2

Core Concepts of Kafka Series - Part 3

Kafka and Node.js

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.

Mainly, we are in the development Era of Microservices. Most of the Companies prefer to build their applications using Microservices.

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.

Reason being, is Many of the UseCases for Microservices are Event Sourcing

Implementating Kafka for Event Sourcing

This is one of the popular usecases where one Microservice talk with another Microservice through Kafka.

event sourcing

Mainly, we will see how to implement the above usecase using Kafka and Node.js

  • User Service - this service handles all the user business logics such as user creation, update and delete.
  • Post Service - this service handles all the operations of posts for an user.

Event Sourcing comes when we an user is deleted, we need to delete all the posts related to user.

When Client make an API call, gateway sends the request to respective Microservice.

If the particular service has some data dependencies with other services, it will send the Data to Other services using Kafka(Event Sourcing).

Other Services SubScribes the Kafka Topics and get the data to do the business operations.

Demo

Screenshot 2019 08 11 at 4 08 29 PM

Complete Source Code can be found here

Summary

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.

References :

EventSourcing - Microservice.io

Event Sourcing,CQRS - Apache Kafka

To Read More

Building a Piano with React Hooks

In this article, we will see how to build a piano with react hooks. Building a P...

TypeScript Basics - The Definitive ...

In this article, we will learn some basics of typescript which helps you to deve...

Here's why podman is more secured t...

In this article we will see about podman and why it is more secured way to run c...

Building a Production - Ready Node....

In this article, we will see how to build a Nodejs, TypeScript Application and d...

Nginx for Front-end Developers

This article is to explain Nginx for Front-end Developers in a much simpler way....

What is gRPC ? How to implement gRP...

Everyone talks about gRPC. Have you ever wonder how it works or how to implement...