zlacker

[parent] [thread] 16 comments
1. jitl+(OP)[view] [source] 2023-07-23 19:36:20
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?

replies(4): >>Xeoncr+i1 >>paulgb+34 >>atombe+59 >>sofixa+Mm1
2. Xeoncr+i1[view] [source] 2023-07-23 19:43:32
>>jitl+(OP)
Queues are often used for two reasons: as a way to throttle processing (just throw it into the queue and drain as you have time) and a way to avoid state loss (process the queue item and only ack/clear it once you've done X, Y, & Z. Of course there are more uses, but these are the two most common.

Depending on the throughput you need, the number of clients pulling/putting into the queue, and other things you can rule out certain options. For example, Redis queue will be one of the fastest choices - but is very limited in capacity (memory size). SQS is basically unlimited capacity, but can often have 150ms or more of time elapse between when you put the item in and when it's available.

3. paulgb+34[view] [source] 2023-07-23 19:57:46
>>jitl+(OP)
MQTT is a protocol rather than an alternative to NATS; NATS supports MQTT (https://docs.nats.io/running-a-nats-service/configuration/mq...)

As far as ideal use cases, we use NATS for https://plane.dev in two ways:

- As a message bus, it is a layer of abstraction on top of the network. Instead of each node needing to establish a connection to every node it needs to connect to, it just connects to a NATS cluster and messages are routed by subject. This is great for debugging because we can "wiretap" messages on a given subject pattern and verify what's being sent. We even have a service that listens on NATS subjects and conditionally turns events into Slack messages.

- It has a built-in RAFT implementation (via JetStream), which we piggyback on when we need to create consensus among nodes.

4. atombe+59[view] [source] 2023-07-23 20:26:49
>>jitl+(OP)
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.

replies(2): >>zerbin+5t >>jadbox+WU
◧◩
5. zerbin+5t[view] [source] [discussion] 2023-07-23 22:41:13
>>atombe+59
It is worth noting that the jetstream API (to me) (not that experienced) to lack some of the features of Kafka w.r.t. replayability - for instance I can’t easily say “go back and re-run messages from X point-in-time”. Instead it may be necessary to write custom handlers for replay or safeguard your systems to be very idempotent (a good pattern in event driven systems, but not one that is explicitly required by Kafkaesque messaging systems).
replies(2): >>atombe+kw >>klabb3+za1
◧◩◪
6. atombe+kw[view] [source] [discussion] 2023-07-23 23:09:09
>>zerbin+5t
Yes, I did not mean to suggest that Jetstream is equivalent to Kafka. It's quite different.
replies(2): >>zerbin+hA >>rcomba+hi4
◧◩◪◨
7. zerbin+hA[view] [source] [discussion] 2023-07-23 23:34:27
>>atombe+kw
Yep, just clarifying for the reader. The use cases/advantages/disadvantages seem to be somewhat different
◧◩
8. jadbox+WU[view] [source] [discussion] 2023-07-24 02:28:53
>>atombe+59
Isn't it a big problem if readers miss messages if either the topic readers go offline briefly or message throughout exceeds readers?
replies(1): >>atombe+SW1
◧◩◪
9. klabb3+za1[view] [source] [discussion] 2023-07-24 05:24:40
>>zerbin+5t
Jetstream has real time replay[1], and you can easily pick a starting time, and continue to stream new events as well.

But yes, to be able to replay without side effects you’ll want to make sure you’re setting up the consumers correctly. That may need some custom logic, but isn’t that necessary with any message queue?

[1]: https://docs.nats.io/using-nats/developer/develop_jetstream

10. sofixa+Mm1[view] [source] 2023-07-24 07:26:03
>>jitl+(OP)
> NATS vs MQTT vs Kafka vs Redis Queue vs Amazon SQS - how do they all stack up

I'm curious why are RabbitMQ and AMQP no longer part of such comparisons (not only your comment, nobody else on this thread has mentioned them).

replies(1): >>jitl+O93
◧◩◪
11. atombe+SW1[view] [source] [discussion] 2023-07-24 11:54:01
>>jadbox+WU
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.

replies(1): >>Kinran+kc2
◧◩◪◨
12. Kinran+kc2[view] [source] [discussion] 2023-07-24 13:07:30
>>atombe+SW1
Jetstream is distributed as an optional part of NATS, so while it exists as a layer on top of NATS Core and provides a different model, describing NATS as entirely stateless is not totally accurate

Though I suspect that Synadia people might do at least one more minor iteration of Jetstream: it still seems a little more complex than it needs to be, unlike Core

replies(1): >>rcomba+6h4
◧◩
13. jitl+O93[view] [source] [discussion] 2023-07-24 17:00:51
>>sofixa+Mm1
At my past job RabbitMQ was an infrequent source of painful surprises. I think it's kinda like HAProxy, a venerable solution that's well known but being replaced in new work more trendy implementations of the same kind of thing.
replies(1): >>sofixa+Xg5
◧◩◪◨⬒
14. rcomba+6h4[view] [source] [discussion] 2023-07-24 22:50:20
>>Kinran+kc2
See https://github.com/nats-io/nats.go/tree/main/jetstream#readm...
replies(1): >>gedw99+dj9
◧◩◪◨
15. rcomba+hi4[view] [source] [discussion] 2023-07-24 22:59:22
>>atombe+kw
IMHO and I would argue that JetStream functionally does much more than Apache Kafka (e.g. stream filtering using subject based addressing, stream with working queue semantics, constraints on streams, compare and set (so you can do CRUD operations), stream sourcing and mirroring, etc...), and has many (most?) of the features of Kafka Streams.
◧◩◪
16. sofixa+Xg5[view] [source] [discussion] 2023-07-25 07:39:07
>>jitl+O93
Interesting, at my past job we used RabbitMQ at decent scale and it was rock solid once the initial kinks around scaling were ironed out (there weren't enough resources for the amount of messages that were thrown at it).
◧◩◪◨⬒⬓
17. gedw99+dj9[view] [source] [discussion] 2023-07-26 08:37:46
>>rcomba+6h4
what do you think of the new JetStream API ?
[go to top]