Replies: 8 comments 12 replies
-
We have been thinking quite a bit on JetStream consumers and filtering, especially beyond just subjects. We have thought down the path of headers a bit, callouts, etc. And the WASM piece still flowing around for sure. This looks pretty interesting, I think json might be one or two cool projects away from just winning 95+% of encodings. I was concerned on this one around the pre-processing step though, but good t explore regardless. Was also looking at these for ideas/inspiration as well. https://github.com/SnellerInc/sneller |
Beta Was this translation helpful? Give feedback.
-
I do believe WASM would be a brilliant idea, not only for header and payload processing but also maybe for extending NATS in many ways (fine grained permissions, custom logic, ...). Of course this comes with many challenges and probably is a mid/long-term move. One could imagine a generic JSON validator implemented as a WASM module for example. My 2 cents 😄 |
Beta Was this translation helpful? Give feedback.
-
For sure, no worries, we are in agreement! Wasm is exciting and there is
a lot of potential.
|
Beta Was this translation helpful? Give feedback.
-
Regarding WASI and WASM i have been using wazero with NATS. Its a great marriage so far. https://github.com/tetratelabs/wazero NO CGO too !!! LIfe is too short for CGO .. |
Beta Was this translation helpful? Give feedback.
-
Any update on extending NATS with WASM UDFs (user-defined function)? |
Beta Was this translation helpful? Give feedback.
-
I am evaluating nats as a potential replacement for google pubsub and I was a bit disappointed to see how filtering works in nats. in pubsub you have your message with metadata attached to it (in nats that would be Headers I think), and you can set filters on these metadata and only them which works well. I was looking at something similar in nats but couldn't find it. What is the current state of filtering ? is there anything available right now beside subject based filtering ? |
Beta Was this translation helpful? Give feedback.
-
I see benefits of more server side filtering that cannot be solved in the subject. Same subject is the core concept for many parts of jetstream (like rollup and max msgs per subject and last msg per subject and so on). There are however many situations where only some of those messages are relevant for a specific consumer (in actionable events world). In the end, the filtering needed would depend on the content of Data. One way to make it more light-weight and avoiding unpacking Data in the server processing would be to use headers and some kind of tagging. So subscription on subjects(!) (with or without wildcards) in combination with server-side evaluation of headers would be beneficial in my cases, specially when the latency between server and client increases or the bandwidth decreases (we do some sat com, low bandwidth and high latency). Currently, we try to solve it with different subjects and looses all optimizations like rollup or "Nats-Expected-Last-Subject-Sequence" that is very useful in sat-com. The solution to first create a header-only consumer and the request the msgs we need creates a lot more roundtrips, and consuming all irrelevant msgs chokes limitated bandwidths as well as drives cost. A first implementation where we can register a callback when we run the server embedded would help a lot. Or at least that would make cost/benefit/impact much clearer and maybe it will becode easier to reason about |
Beta Was this translation helpful? Give feedback.
-
Any progress in this part of jetstream? |
Beta Was this translation helpful? Give feedback.
-
This feature may be out of scope since NATS is intentionally payload agnostic, however, related discussions have come up in Slack a handful of times so I wanted to start a discussion to document ideas.
What prompted me this time, was that I came across a recent Tim Bray post and Go library which implements JSON-based structural pattern matching. He had worked for AWS and help implement the EventBridge pattern matcher. This new library is a re-implementation of that and he boasts that it is quite fast (but is it NATS fast 😉).
Currently, a consumer supports filtering on a single subject (multiple subjects have been requested). For users using JSON-encoded payloads, one or more JSON patterns could be defined on the consumer for additional layer of server-side filtering. Here is an example from the post.
The big trade-off here, is that this introduces runtime cost and possible defects (bad JSON payload) although there may be ways to prevent bad data by checking for JSON validity when a published message is received. That said, this would be opt-in and the default fast path would remain the same. Only if the pattern matching configuration is specified would this additional runtime work need to be performed.
Another idea that had been discussed before was to use a wasm module, however that would require more effort (IMO) on both server-side integration and on developers at this time.
Beta Was this translation helpful? Give feedback.
All reactions