Start
monoblok documentation
monoblok is a small NATS-compatible message processor. It rounds, dedupes, smooths, demuxes and routes messages in flight, using rules written in a small language called patchbay, so subscribers do not have to.
The problem it solves#
Sensor and market data feeds often publish more frequently, or at greater precision, than subscribers need. Each subscriber then implements similar rounding, filtering and deduplication logic.
A separate processing service can republish these feeds, but it also needs deployment and maintenance.
monoblok applies patchbay rules before fan-out. For example, this rule rounds sensor readings and suppresses duplicates:
; Round to 1dp, drop duplicates, emit on the .stable sub-subject.
(on "sensors.*"
(-> payload-float
(round 1)
(squelch)
(publish! (subject-append "stable"))))Subscribers that want the conditioned value listen to sensors.*.stable. The raw stream stays available for anyone who needs it. Here is that rule fed seven jittery readings:
in sensors.temp 42.01
out sensors.temp.stable 42
in sensors.temp 42.04
in sensors.temp 42.08
out sensors.temp.stable 42.1
in sensors.temp 42.12
in sensors.temp 43.00
out sensors.temp.stable 43
in sensors.temp 43.00
in sensors.temp 43.01Three ways to run it#
monoblok speaks the NATS protocol, so existing clients connect without changes.
- Tap into existing NATS. monoblok subscribes to selected subjects on your NATS environment, treats them as private patchbay input, then emits back only the cleaned or derived subjects your rules choose. See import.
- Signal conditioning front door. Publishers send raw events to monoblok, monoblok cleans them, then forwards selected subjects to a NATS cluster. See export.
- Standalone broker. NATS clients connect directly to monoblok for lightweight NATS-core pub/sub with signal conditioning built in.
For the front door pattern, change the publishers' server address to monoblok and configure an export to the cluster. Subscribers continue to connect to the cluster and use the processed subjects.
Five-minute start#
Install the binary (macOS or Linux), or use the container image. Install and run has the details.
curl -fsSL https://raw.githubusercontent.com/lexvicacom/monoblok/main/scripts/start.sh | bash
./monoblok-*/monoblok --port 14222 --patchbay ./monoblok-*/patchbay.ednWith the NATS CLI in two more terminals, subscribe and publish:
nats -s nats://127.0.0.1:14222 sub 'sensors.>'
nats -s nats://127.0.0.1:14222 pub sensors.temp 21.04
nats -s nats://127.0.0.1:14222 pub sensors.temp 21.01
nats -s nats://127.0.0.1:14222 pub sensors.temp 21.42You can try rules without a server or a NATS client at all. --soundcheck reads SUBJECT|payload rows on stdin and prints what the rules publish:
printf 'sensors.temp|31\n' | monoblok --soundcheck examples/sensors.ednA public demo server runs on demo.monoblok.host:4222, and the live demo page connects to it without a local install.
Where to go next#
- Patchbay guideThe rule language: syntax, threading, state, and the EDN, YAML and JSON spellings.
- Forms referenceEvery form with its arguments, behaviour and a worked snippet.
- ExamplesRunnable patchbays from a five-line sensor rule to a market data firehose.
- LVC, stats and snapshotsLast-value streams for late joiners, live counters, and warm restarts.
- NATS clients, auth and HTTPProtocol coverage, tokens, TLS, and the HTTP/SSE adapter for browsers.
- Export, import and JetStreamPairing monoblok with a real NATS cluster, including JetStream replay.
Why put this at the broker#
Processing before fan-out avoids repeating the same operations in every subscriber. A patchbay rule can round temperatures, suppress GPS jitter or filter price changes, and publish the result on a subject shared by all consumers.
The last-value cache serves a different purpose: a new subscriber can receive the most recent value immediately rather than waiting for the next event. See LVC, stats and snapshots for cache configuration and restart behaviour.
When it is not the right tool#
monoblok is a core NATS server with rules, not a replacement for a cluster. It has no JetStream storage, no clustering and no message headers on its own listener. It can consume JetStream messages and forward selected subjects to a NATS cluster.
If plain publish and subscribe is all you need, nats-server is the better choice.
More reading#
- The introductory blog post covers where the idea came from, and there are more posts about monoblok on the blog.
- tinyblok runs a subset of patchbay on ESP32 boards, relaying cleaned sensor data into NATS.
- The Markdown docs these pages are built from live in the repository.
MIT licensed · © 2026 Alex Reid
Lexvica offers solutions built with monoblok.