Self-host nsq
v1.3.0Realtime distributed messaging and work queue platform
docker run --name lookupd -p 4160:4160 -p 4161:4161 nsqio/nsq /nsqlookupd- Stars
- 25 776
- Ports
- 4150 (nsqd TCP interface for producer/consumer clients), 4151 (nsqd HTTP API (publish, stats, admin)), 4152 (nsqd HTTPS API), 4160 (nsqlookupd TCP interface used by nsqd broadcasts), 4161 (nsqlookupd HTTP discovery and admin interface), 4171 (nsqadmin web UI)
nsqio/nsqWhat is nsq?
NSQ shuttles streams of work between services in real time and is aimed at very high throughput - the project describes operating at a scale of billions of messages daily. Producers publish to topics, and each topic fans out into channels: a channel represents one downstream consumer group and gets its own copy of the stream, while delivery within a channel is spread over the clients connected to it. Nothing needs declaring up front, since a topic or channel comes into being on the first publish or subscribe, and nsqlookupd lets consumers locate the producers of a topic at runtime, so clusters grow by adding nsqd nodes instead of a central broker. Buffers are kept in memory and spill to disk automatically once a tunable watermark is passed; note that persistence is not the default unless the in-memory queue length is set to zero. Payload contents are irrelevant to the system (JSON, MsgPack, Protocol Buffers or raw bytes all work), and because publishing, statistics and topic/channel administration are also exposed over HTTP, a plain curl request is a usable producer. The bundled nsqadmin web UI shows live aggregate cluster stats and lets operators create, pause, empty or delete topics and channels, while companion command-line tools (nsq_stat for polling, nsq_tail for stdout, plus archiving utilities like nsq_to_file and nsq_to_http) cover the common introspection jobs. Running it yourself means the dependency-free daemons - written by Matt Reiferson and Jehiah Czebotar with backing from Bitly - unpacked from tarballs for Linux, macOS, FreeBSD and Windows, or the nsqio/nsq container image with a short compose stack of the three services; every setting is a command-line flag or config-file key. TLS, an external authorization server, statsd and Graphite metrics, and admin-action notification webhooks are optional extras. The current stable release is v1.3.0.
nsq alternatives
automqSelf-hosted, open-source Apache Kafka fork with stateless brokers that store logs on S3 or MinIO and rebalance partitions in seconds.Compareautomq with nsq
forqForq is a self-hosted, open-source message queue on SQLite running as a single binary or Docker container with admin UI, metrics, DLQ, and SDKs.Compareforq with nsq
CentrifugoOpen-source, self-hosted real-time messaging server with PUB/SUB over WebSocket, SSE and gRPC, scaling via Redis, PostgreSQL or NATS, plus an embedded admin UI.CompareCentrifugo with nsq
RabbitMQOpen-source messaging and streaming broker for AMQP, MQTT, STOMP and streams, with a web UI and Prometheus metrics. Self-hosted via Docker or packages.CompareRabbitMQ with nsq
netdataNetdata is an open-source, self-hosted infrastructure monitoring platform with per-second metrics, automated dashboards, ML anomaly detection, and zero-config deployment.Comparenetdata with nsq
questdbSelf-hosted, open-source time-series database with SAMPLE BY and ASOF join SQL, QuestDB Wire Protocol ingestion, PGWire support and a web console.Comparequestdb with nsq
EMQXThe most scalable and reliable MQTT broker for AI, IoT, IIoT and connected vehiclesCompareEMQX with nsq
VerneMQVerneMQ is a self-hosted, open-source MQTT broker built on Erlang/OTP that scales to handle millions of IoT connections with low latency and fault tolerance.CompareVerneMQ with nsq
Should you self-host nsq?
nsq scores 70/100 on selfhost.directory (how scoring works) and ranks #5 of 12 in Message Broker. It has 25 776 GitHub stars, +7 in the last 30 days.
There was no stable release in the past 12 months, so check the repository's recent activity before you rely on it.
Setup is moderate: expect some configuration beyond a single command. An official Docker image is available. It is MIT-licensed and written mostly in Go.
Its closest alternative on selfhost.directory is Apache Kafka (82/100, 34 195 stars). It scores higher overall, so compare the two before you pick. See nsq vs Apache Kafka side by side.
Features
- Admin web UI
- Bundled CLI utilities
- Client compression negotiation
- Data format agnostic
- Deferred message delivery
- Disk-backed queue overflowMessages are not durable by default.
- Distributed topology with no SPOF
- External authorization serverAvailable in nsqd v0.2.29+
- Horizontal scaling without brokers
- HTTP publish and admin API
- Load-balanced and multicast routing
- Low-latency push delivery
- Pub-sub with per-consumer channels
- Runtime consumer discovery (nsqlookupd)
- TLS transport security
nsq README
- Source: https://github.com/nsqio/nsq
- Issues: https://github.com/nsqio/nsq/issues
- Mailing List: nsq-users@googlegroups.com
- IRC: #nsq on freenode
- Docs: https://nsq.io
- Twitter: @nsqio
FAQ
When would I want to use Writer then?
Use Writer when performance matters, because its TCP PUB and MPUB commands have less overhead than the HTTP equivalents.
Is the Tornado IOLoop required to publish?
No, the nsqd HTTP endpoints /pub and /mpub work from any language, and /mpub batches publishes atomically.
Why are you forcing me to use Tornado?
pynsq started as a consumer-focused library and NSQ's push-oriented protocol is simpler to consume in Python with an asynchronous framework.
Can NSQ do RPC?
It is possible but NSQ was not designed for that use case.
How are new topics announced to the cluster?
The first PUB or SUB creates the topic on an nsqd, its metadata propagates to the configured nsqlookupd, and readers discover it by polling lookupd.
Are there any limitations to the number of topics and channels a single nsqd can support?
There are no built-in limits; only the memory and CPU of the host running nsqd constrain it.
How do you recommend naming topics and channels?
Name a topic after the data in the stream and a channel after the work its consumers do, for example topic encodes and channel archive.
How can I mitigate deleting-topic failures during publish?
Deleting topics is infrequent; orchestrate timing so publishes that would recreate a topic wait until enough time has passed since the deletion.
When can a PUB or MPUB fail?
When the topic name breaks the naming spec, the message is too large, the topic is being deleted, nsqd is exiting cleanly, or the client connection fails.
Why force a client to handle responses to the TCP protocol's PUB and MPUB commands?
The protocol was kept simple and consistent so that safe behaviour is the default mode of operation.
Do I need a client library to publish messages?
No, you can publish through the HTTP /pub and /mpub endpoints, and most deployments do exactly that.
How many nsqlookupd should I run?
Only a few; 3 or 5 works well up to several hundred hosts and thousands of consumers, since lookupd nodes answer queries without coordinating and metadata is eventually consistent.
I just want to use nsqd as a work queue on a single node, is that a suitable use case?
Yes, nsqd runs standalone fine; nsqlookupd is only useful in larger distributed environments.
Why can't nsqlookupd be used by producers to find where to publish to?
NSQ only solves consumer-side discovery; the topic does not exist before the first publish, so producers publish to a local nsqd instead.
What is the recommended topology for nsqd?
Run an nsqd next to every service that produces messages; nsqd is lightweight with a bounded memory footprint, so it co-exists well and forms an independent sharded silo of data per host.
More in Message Broker
RabbitMQOpen-source messaging and streaming broker for AMQP, MQTT, STOMP and streams, with a web UI and Prometheus metrics. Self-hosted via Docker or packages.
RedisRedis is a self-hosted, open-source in-memory data structure server used as a database, cache, message broker, and vector query engine with sub-millisecond latency.
ValkeySelf-hosted, open-source Valkey is an in-memory key-value database for caching, queues and primary data, with replication, Sentinel failover and cluster sharding.
activemqThe open-source, self-hosted Apache ActiveMQ message broker handles JMS, AMQP, MQTT, STOMP and REST traffic from Java, C, Python and .Net clients.
Apache KafkaApache Kafka is a self-hosted, open-source event streaming platform for high-performance data pipelines and mission-critical applications.
automqSelf-hosted, open-source Apache Kafka fork with stateless brokers that store logs on S3 or MinIO and rebalance partitions in seconds.
beanstalkdbeanstalkd is a self-hosted, open-source work queue: a small C daemon where producers put jobs into named tubes and workers reserve, bury or kick them over plain TCP.
BunkerMBunkerM is a self-hosted, open-source MQTT platform bundling Eclipse Mosquitto with a web dashboard, ACL management, message history, anomaly detection, and AI.
Eclipse MosquittoSelf-hosted open-source MQTT broker for MQTT 5.0, 3.1.1 and 3.1 with TLS, WebSockets, bridging, ACLs and a C client library plus CLI pub/sub tools.
forqForq is a self-hosted, open-source message queue on SQLite running as a single binary or Docker container with admin UI, metrics, DLQ, and SDKs.
gearmandGearman is a self-hosted, open-source job server for parallel processing, load balancing, and cross-language function calls.
HiveMQ Community EditionHiveMQ Community Edition is an open-source Java MQTT broker with full MQTT 3.x and MQTT 5 support, TLS and WebSocket listeners, a Java extension SDK and an embedded mode.

0 comments