feat: add NATS pub/sub backend - #4498
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
|
Benchmark resultsCompared against |
️✅ There are no secrets present in this pull request anymore.If these secrets were true positive and are still valid, we highly recommend you to revoke them. 🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6d35bfc to
6b97c0e
Compare
6b97c0e to
7e55a74
Compare
|
|
7e55a74 to
a4707f7
Compare
6b68e64 to
6df9e5f
Compare
|
GitHub marked this PR as merged in error — the NATS backend has not landed on While reordering the stack, this PR's base was pointed at Merged PRs can't be reopened, so the work continues in #4550 — same branch, same change, based on Nothing was lost; only the PR number changed. The review discussion here is still the earlier context. |
Description
Adds NATS as a pub/sub backend, selectable per deployment via
SERVER_MSGQUEUE_PUBSUB_KIND=nats+SERVER_MSGQUEUE_PUBSUB_NATS_URL. NATS implements only the best-effort pub/sub side of the split from #4480; durable queues stay on RabbitMQ/Postgres.Core NATS, no JetStream, so delivery is at-most-once — which matches what the pub/sub path already promises.
Stacked on #4548 (pub/sub Prometheus instrumentation), so that the metrics used to evaluate this backend are already deployed and have a baseline before NATS is enabled anywhere. Review #4548 first; this PR's diff is NATS-only.
Type of change
What's Changed
internal/msgqueue/natsplus config, docs, and a compose service.max_payloadagainst the 16MiB the durable RabbitMQ path allows. Task stream events routinely exceed the NATS default of 1MiB, and a refused startup is easier to diagnose than an oversized publish failing later under load.ReconnectBufSize(-1)means publishes error out rather than silently buffering messages that a best-effort subscriber will never wait for.max_payload.SERVER_MSGQUEUE_PUBSUB_NATS_SUBJECT_PREFIX(defaulthatchet.pubsub). The other backends namespace installations at the connection level (a RabbitMQ vhost, a Postgres database); NATS namespaces by subject, so this is the parity knob for installations sharing a NATS server.Checklist
Changes have been:
Testing
The integration suite covers tenant fanout to multiple subscribers, a scheduler-topic roundtrip, an 8MiB payload, oversized-message chunking, a compressed roundtrip, and a custom subject prefix (asserted against a raw NATS subscription on the expected subject).
The NATS server needs
max_payload: 16777216; seehack/dev/nats-server.conf, which the compose service mounts.Notes for reviewers
Rebased onto
mainafter #4480 merged. #4480's review absorbed several refactors this branch originally carried, so they are no longer in the diff:mainmoved the wholeCompressorintomsgqueue, going further than this branch didMessage.CopyWithPayloads—mainlanded the same shallow-copy fix asClone(), which the NATS chunking path now usesrabbitmqandpostgrespub/sub changes — after rebasing, those files were identical tomainTwo things the rebase surfaced, both fixed here:
Subpath claimed the durable RabbitMQ path compresses payloads in place. refactor: separate pub/sub interface from durable task queue #4480 fixed exactly that, so it is now a short note explaining that the decompress branch is defensive parity withrabbitmq/pubsub.goSubpath was not resettingCompressed = falseafter decompressing, unlikerabbitmq/pubsub.goOne thing worth a reviewer's opinion:
hack/dev/nats-server.confsetsmax_payload: 16777216for RabbitMQ parity, and NATS itself warns at startup that payloads over 8MiB "are generally discouraged and could lead to poor performance". Parity is the conservative choice for a drop-in backend, but if we don't actually need >8MiB pub/sub messages it would be better to find that out before rollout.Related
🤖 AI Disclosure
I acknowledge that an LLM was used in the creation of this Pull Request, in accordance with Hatchet's AI_POLICY.md.
Details: Cursor agent implemented the NATS pub/sub backend, config/docs/compose wiring, and tests from a reviewed plan, and performed the rebase onto
mainafter refactor: separate pub/sub interface from durable task queue #4480 merged.