NATS & Kafka: random notes
This is not NATS vs Kafka by any means — just jotting down some info. NATS recently joined CNCF (which host projects like Kubernetes, Prometheus etc. — look at the Golang dominance here!) and that’s when it caught my attention
Here are a few things which came to mind….
Might add more later
Where — Kafka runs on JVM (Scala to be specific), NATS is written in Go
Protocol — Kafka is binary over TCP as opposed to NATS being simple text (also over TCP)
Messaging patterns — Both support pub-sub and queues, but NATS supports request-reply as well (sync and async)
- NATS has a concept of
queue(with a unique name of course) and all the subscribers hooked on same queue end up being a part of the same
queue group. Only one of the (potentially multiple) subscribers gets the message. Multiple such queue groups would also receive the same set of messages. This makes it a
hybridpub-sub (one-to-many) and queue (point-to-point)
- Same thing is supported in Kafka via
consumer groups which can pull data from one or more topics
Stream processing — NATS does not support stream processing as a first class feature like Kafka does with
Kafka clients use a poll-based technique in order to extract messages as opposed to NATS where the server itself routes messages to clients (maintains an
- NATS can act pretty sensitive in the sense that it has the ability to cut off consumers who are not keeping pace with the rate of production as well as clients who don’t respond to heartbeat requests.
- The consumer liveness check is executed by Kafka as well. From what I recall, this is done/initiated from the client itself & there are complex situations that can arise due to this (e.g. when you’re in a message processing loop and don’t poll ). There are a bunch of configuration parameter/knobs to tune this behavior (on client side)
Delivery semantics — NATS supports
at-most once (and
at-least-once with NATS streaming) as opposed to Kafka which also supports
Sharding/Partitioning — NATS doesn’t seem to have a notion of partitioning/sharding messages like Kafka does
External dependency — None in case of NATS. Kafka requires Zookeeper
Originally published at simplydistributed.wordpress.com on March 30, 2018.