When is it better to use websockets versus a message broker such as Kafka?

Viewed 5699

As a product scales, APIs and two tier architecture incurs bottlenecks, data contention, downtime. Messages can become lost, if there are thousands or millions of requests & activity

What makes websocket connections beneficial vs Kafka? What are the best use cases for each?

Is there an example such as a large scale chat application where a hybrid of both technologies are necessary?

1 Answers

Websockets should be used when you need real-time interactions, such as propagating the same message to multiple users (group messaging) in a chat app.

Kafka should be used as a backbone communication layer between components of a system. It fits really well in event-driven architectures (microservices).

I see them as 2 different technologies which have been developed for 2 different purposes.

Kafka, for example, allows you to reply messages easily, because they are stored on the local disk (for the configured topic retention time). Websockets are based on TCP connections (two-way communication), so they have a different use-case spectrum.

Related