Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rate-limit for publishing messages #4891

Open
AbstractiveNord opened this issue Dec 16, 2023 · 7 comments
Open

Rate-limit for publishing messages #4891

AbstractiveNord opened this issue Dec 16, 2023 · 7 comments
Assignees
Labels
proposal Enhancement idea or proposal

Comments

@AbstractiveNord
Copy link

Proposed change

Option per publisher, which can block or even cause a disconnection for user, spamming into NATS network.

Use case

Every time when NATS publisher is not 100% trusted entity.

Contribution

Yes.

@AbstractiveNord AbstractiveNord added the proposal Enhancement idea or proposal label Dec 16, 2023
@derekcollison derekcollison self-assigned this Dec 16, 2023
@derekcollison
Copy link
Member

So this is not about sending to other subjects, which we can lock down, but for valid subjects just to rate limit yes?

@AbstractiveNord
Copy link
Author

So this is not about sending to other subjects, which we can lock down, but for valid subjects just to rate limit yes?

Yes. Even for allowed subjects, if we have NATS connection on client side, for example, in JS code on web page, we cannot protect the NATS network by blocking spam. This is the problem, which causes irrelevant backend, doing nothing more than just rate-limiting and proxy client HTTP requests into NATS requests.

@AbstractiveNord
Copy link
Author

It's probably good idea to have a bunch of distributed clustered NATS Jetstream KV buckets with TTL configured, used by Core NATS for rate-limit users. Core NATS acts like sticky proxy, so by implementing this approach, it's possible to have sync hot cache on Core NATS proxies, updates through NATS KV watch subscription. Welcome to discuss, just first idea.

@derekcollison
Copy link
Member

Not following that last comment.

The server code base does have a rate limiter, currently only in use as an opt-in for JetStream consumers.

That could be utilized possibly.

@tjad
Copy link

tjad commented Mar 10, 2024

I think 1 consideration for this topic is about whether or not a managed cluster of NATS is in use.

I have seen in another thread the consideration using TC #346 (comment) . This does sound plausible if the solution is self-managed, then using the TC sounds like a viable option at a more ideal level. My concern comes in for managed clusters. It should probably be the onus of the cluster provider to allow such functionality/feature, however this can't be guaranteed as a feature between providers.

Also, TC is rate limiting at the bandwidth level, it may be more convenient to rate limit at a per message level - this would alleviate requirement to understand and do calculations around the message size.

Just food for thought.

@dragonballa
Copy link

Not following that last comment.

The server code base does have a rate limiter, currently only in use as an opt-in for JetStream consumers.

That could be utilized possibly.

I'm facing this exact situation where we don't know if the publisher is trustable or not. Can easily spam/DDOS

I'm looking for a solution I can use NOW

Is KV the way to go? Not sure what that rate limiter code you speak of looks like (or know where it is).

@derekcollison
Copy link
Member

Nothing to limit the inbound rate outside of network throughput and max payload size at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Enhancement idea or proposal
Projects
None yet
Development

No branches or pull requests

4 participants