DEV Community

Discussion on: Realtime Chat app using Kafka, SpringBoot, ReactJS, and WebSockets

Collapse
 
axellageraldinc profile image
Axellageraldinc Adryamarthanino

Hi, great article!
I have a question though, why use kafka at all if we're already using websocket? 'Cause websocket also streams the data to the client alright. I would really appreciate if you answer my question 😊

Collapse
 
saiboyina profile image
SAI BOYINA

What if receiver not available? kafka works as a mediator to hold the message until receiver gets the message. In case of group message the unique message_id being used as a key and deliver to whole group of members whenever they are available by having a service which acts as a push message service for such users.

Collapse
 
nonefornothing profile image
None for Nothing

because you need websocket , if you want display data to browser.
if you only use kafka and try rest api to display to browser , then it can't be works ( data thats you transfer is null). its happen because when you produce something to kafka, kafka automatically consume that data.
btw : its happen to me :D

Collapse
 
axellageraldinc profile image
Axellageraldinc Adryamarthanino

Hi, thanks for the reply.
Though my question was about using only websocket without kafka, not the other way around.
Could you help on the question? Big thanks in advance!

Thread Thread
 
nonefornothing profile image
None for Nothing

yes , you can do it, if you only using websocket for event streaming.

Collapse
 
alqaholic profile image
Rohit Krishnan

Using only websockets would be great for this application (there is no need for an additional dependancy on kafka).
Suppose you have a more complex chat application (that is safe for cats 😅); Eg:- A image you send needs to be scanned for dogs before sending it (or else it'll scare cats).
In this case you can have a dog-detection-service that listens for events on the image-topic and runs the image through a ML model that scans for dogs.
The service can then publish to a messages-topic which can then be consumed by a messages-service that exposes a websocket endpoint for the UI to consume.

This way kafka helps to isolate application logic.. the messages-service just needs to send events in the messages-topic to connected clients and the dog-detection-service just has to process events on the image-topic before publishing it to the messages-topic.

Collapse
 
wilfoderek profile image
Wilfo Iván

Let's suppose the next scenario:
The user is chatting and suddenly he/she lost connection due a intermitation so when getting backs the internet signal the message must appears again with their respective status, so this persistence you get it with kafka.

Some comments have been hidden by the post's author - find out more