NSQ
Real-time distributed messaging platform.
Overview
NSQ is a realtime distributed messaging platform developed by Bitly, designed to operate at scale and handle billions of messages per day. Built in Go, NSQ emphasizes simplicity, fault-tolerance, and high availability through its distributed topology that eliminates single points of failure. The platform consists of three core daemons: nsqd (message queue daemon), nsqlookupd (topology discovery service), and nsqadmin (web-based administration interface).
This Docker stack deploys a complete NSQ cluster with nsqlookupd providing service discovery on ports 4160/4161, nsqd handling message queuing on ports 4150/4151, and nsqadmin offering web-based monitoring and administration on port 4171. The architecture allows producers and consumers to discover each other dynamically through nsqlookupd, while nsqd nodes can be scaled horizontally without coordination. Messages are distributed across available nsqd instances, and the system continues operating even if individual components fail.
Developers building event-driven applications, DevOps teams implementing microservice communication, and organizations requiring reliable message delivery will find this NSQ deployment valuable. The platform excels in scenarios requiring guaranteed message delivery, real-time data processing pipelines, and distributed system coordination where traditional message brokers might introduce complexity or single points of failure.
Key Features
- Distributed topology with automatic service discovery via nsqlookupd eliminating configuration management overhead
- Guaranteed message delivery with configurable retry mechanisms and dead letter queue support
- Memory and disk-based message persistence with configurable sync intervals for durability
- Built-in message deduplication and ordering guarantees within individual topics and channels
- HTTP and TCP protocol support for both publishing and consuming messages with JSON API
- Real-time web interface through nsqadmin for monitoring message rates, queue depths, and node health
- Automatic load balancing across multiple nsqd instances without manual partitioning
- Channel-based fan-out messaging allowing multiple consumer groups per topic
Common Use Cases
- 1Event-driven microservices architecture requiring reliable inter-service communication
- 2Real-time analytics pipelines processing user activity streams and application metrics
- 3Distributed job processing systems with task queuing and worker coordination
- 4IoT data ingestion platforms handling sensor data from thousands of devices
- 5E-commerce order processing workflows requiring guaranteed delivery and audit trails
- 6Chat applications and notification systems requiring real-time message distribution
- 7Log aggregation and processing systems collecting data from distributed applications
Prerequisites
- Docker Engine 20.10+ and Docker Compose v2 for container orchestration support
- Minimum 512MB RAM available for the NSQ cluster with additional memory for message buffering
- Available ports 4150-4151 (nsqd), 4160-4161 (nsqlookupd), and 4171 (nsqadmin) on the host system
- Basic understanding of pub/sub messaging patterns and distributed systems concepts
- Network connectivity between containers and familiarity with NSQ's HTTP API for integration
- Understanding of Go-based application logging and debugging for troubleshooting NSQ components
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 nsqlookupd: 3 image: nsqio/nsq:latest4 container_name: nsqlookupd5 command: /nsqlookupd6 ports: 7 - "4160:4160"8 - "4161:4161"910 nsqd: 11 image: nsqio/nsq:latest12 container_name: nsqd13 command: /nsqd --lookupd-tcp-address=nsqlookupd:416014 ports: 15 - "4150:4150"16 - "4151:4151"17 depends_on: 18 - nsqlookupd1920 nsqadmin: 21 image: nsqio/nsq:latest22 container_name: nsqadmin23 command: /nsqadmin --lookupd-http-address=nsqlookupd:416124 ports: 25 - "4171:4171"26 depends_on: 27 - nsqlookupd.env Template
.env
1# No additional config neededUsage Notes
- 1Docs: https://nsq.io/overview/design.html
- 2Admin UI at http://localhost:4171, nsqd on ports 4150 (TCP) / 4151 (HTTP)
- 3nsqlookupd handles service discovery on ports 4160/4161
- 4Publish: curl -d 'message' http://localhost:4151/pub?topic=test
- 5No single point of failure - fully distributed
- 6Written in Go - simple, performant, fault-tolerant
Individual Services(3 services)
Copy individual services to mix and match with your existing compose files.
nsqlookupd
nsqlookupd:
image: nsqio/nsq:latest
container_name: nsqlookupd
command: /nsqlookupd
ports:
- "4160:4160"
- "4161:4161"
nsqd
nsqd:
image: nsqio/nsq:latest
container_name: nsqd
command: /nsqd --lookupd-tcp-address=nsqlookupd:4160
ports:
- "4150:4150"
- "4151:4151"
depends_on:
- nsqlookupd
nsqadmin
nsqadmin:
image: nsqio/nsq:latest
container_name: nsqadmin
command: /nsqadmin --lookupd-http-address=nsqlookupd:4161
ports:
- "4171:4171"
depends_on:
- nsqlookupd
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 nsqlookupd:5 image: nsqio/nsq:latest6 container_name: nsqlookupd7 command: /nsqlookupd8 ports:9 - "4160:4160"10 - "4161:4161"1112 nsqd:13 image: nsqio/nsq:latest14 container_name: nsqd15 command: /nsqd --lookupd-tcp-address=nsqlookupd:416016 ports:17 - "4150:4150"18 - "4151:4151"19 depends_on:20 - nsqlookupd2122 nsqadmin:23 image: nsqio/nsq:latest24 container_name: nsqadmin25 command: /nsqadmin --lookupd-http-address=nsqlookupd:416126 ports:27 - "4171:4171"28 depends_on:29 - nsqlookupd30EOF3132# 2. Create the .env file33cat > .env << 'EOF'34# No additional config needed35EOF3637# 3. Start the services38docker compose up -d3940# 4. View logs41docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/nsq/run | bashTroubleshooting
- nsqd fails to connect to nsqlookupd: Verify nsqlookupd is running and accessible on port 4160, check Docker network connectivity between containers
- Messages not being delivered to consumers: Confirm topic and channel names match exactly, check nsqadmin interface for queue depth and consumer connections
- nsqadmin shows 'No nsqd nodes' error: Ensure nsqd has registered with nsqlookupd by checking logs, verify nsqlookupd HTTP address configuration
- High memory usage in nsqd: Adjust message retention settings and sync intervals, consider scaling to multiple nsqd instances to distribute load
- Connection refused on HTTP endpoints: Verify port mappings match container internal ports, check firewall rules and Docker network configuration
- Topics not appearing in nsqadmin: Publish at least one message to create the topic, ensure nsqd is properly connected to nsqlookupd for discovery
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Ad Space
Shortcuts: C CopyF FavoriteD Download