zlacker

[return to "High-Performance server for NATS.io, the cloud and edge native messaging system"]
1. jitl+dM4[view] [source] 2023-07-23 19:36:20
>>Kinran+(OP)
With all the message queue whatever thingies, as an outside I’m quite confused about ideal use cases.

NATS vs MQTT vs Kafka vs Redis Queue vs Amazon SQS - how do they all stack up?

◧◩
2. atombe+iV4[view] [source] 2023-07-23 20:26:49
>>jitl+dM4
NATS is not a queue. It's distributed pub/sub message broker for communicating between applications.

NATS's only responsibility is to route messages in near-real-time from publishers to consumers. Messages are ephemeral and dropped immediately after delivery; if nobody is listening, the messages vanish. Messages are only queued temporarily in RAM if the consumer is busy, and they can get dropped if a consumer doesn't handle them fast enough. In short, NATS is very lightweight and fast, and designed for things that are lightweight and fast. It's like a kind of distributed socket mechanism, and works best as a communication primitive you build stuff on top of (like TCP or UDP) rather than a fully fledged system.

So it's very different from Kafka and other types of queues that are durable and database-like. Kafka is good for "fat pipes" that centralize data from producers into a log which is then consumed by massively parallel sets of consumers, and you don't constantly change this topology. NATS is good for networks of fast-changing producers and consumers that send small messages to each other, often one-on-one, although any fan-out topology works. It's great for firehose-type routing. For example, imagine you want your app to produce lots of different kinds of telemetry. Your app just sends messages to a topic "telemetry" or maybe a dotted topic like "telemetry.iostats" or "telemetry.errors". Then a client can "tap" into that topic by listening to it. If no client is listening, the firehose goes nowhere. But then a client can tap into "telemetry.errors" and get just the stream of error messages. Topics are just strings, so you can create unique topics for temporary things; an app can send a message to another app like "hey, do some work and then send the result to my temporary topic foobar726373".

NATS is particularly notable for its "just works" design. The clustering, for example, ties together brokers with no effort. Clients typically don't need any configuration at all, other than the name of a NATS server.

NATS can be used as a low-level component to build stateful stuff. NATS Jetstream is a Kafka-like solution that stores durable logs, and uses NATS as its communication protocol. Liftbridge is another one.

◧◩◪
3. jadbox+9H5[view] [source] 2023-07-24 02:28:53
>>atombe+iV4
Isn't it a big problem if readers miss messages if either the topic readers go offline briefly or message throughout exceeds readers?
◧◩◪◨
4. atombe+5J6[view] [source] 2023-07-24 11:54:01
>>jadbox+9H5
You wouldn't/shouldn't choose NATS if your application needs different semantics.

NATS does not have stateful storage. So when a consumer disconnects and reconnects, there is nowhere for NATS to store the messages temporarily. You can solve this by storing messages in a stateful storage first, then use NATS as a way to distribute them. You would need your own mechanism to replay messages on reconnect. This is coincidentally what Jetstream does. It uses NATS internally as a network protocol, but it's a separate thing.

[go to top]