ZeroMQ DEALER doesnt receive response from ROUTER in DEALER/ROUTER configuration
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
ZeroMQ is an asynchronous messaging library aimed at use in distributed or concurrent applications. It provides several communication patterns through a variety of socket types. The DEALER and ROUTER socket types are part of ZeroMQ's scalability protocols and can be used to build complex communication structures. However, sometimes developers encounter an issue where a DEALER socket does not receive responses from a ROUTER socket. This article covers this problem extensively, including possible causes and solutions, with technical explanations and examples.
Understanding DEALER and ROUTER Sockets
DEALER Socket
The DEALER socket type is a more complex version of the REQ (Request) socket. It can send and receive messages in any order, and it does not have the strict send/receive alternation restriction that REQ sockets have. This makes DEALER ideal for asynchronous operations.
ROUTER Socket
The ROUTER socket is used to route incoming messages to appropriate destinations based on identifying information in the message. This socket type can hold multiple connections and decide to whom to send the messages based on the identifiers embedded in the message envelope.
Common Reasons DEALER Doesn't Receive Responses from ROUTER
- Message Routing Identifiers (IDs) Corruption: ROUTER sockets use identifiers to decide the destination of the message. If these identifiers are missing or corrupted, ROUTER will fail to send the message back to the correct DEALER socket.
- High Water Mark (HWM) Settings: ZeroMQ uses a high-water mark to manage queue sizes. If the ROUTER's HWM is reached, it might start dropping messages, resulting in the DEALER not receiving responses.
- Mismatched or Misconfigured Sockets: Configuration errors like binding to incorrect endpoints or misconfiguration of socket options (like ZMQ_IDENTITY) can also lead to communication failures.
- Thread Safety Issues: ZeroMQ sockets are not thread-safe. Using the same socket from multiple threads without proper locking mechanisms can lead to unpredictable behavior and lost messages.
Technical Explanation with Example
Here’s a simple example to demonstrate a DEALER and ROUTER communication pattern and highlight a typical mistake:
In this example, if the identity frame and the message frame are not properly sent by the ROUTER, the DEALER might not receive the expected message. The problem lies in the misuse of zmq.SNDMORE: forgetting to add it can lead to improper message composition, resulting in undelivered responses.
Troubleshooting Steps
- Check Socket Configuration: Ensure both sockets are correctly configured, and connect to the intended endpoints.
- Verify ZMQ Identity: Make sure that the DEALER and ROUTER sockets have appropriate identities set if routing based on identity.
- Monitor Queue Sizes: Be aware of the high water mark settings; consider adjusting them if messages are dropping unexpectedly.
- Implement Proper Synchronisation: Make sure each socket is being accessed by one thread at a time or implement an appropriate locking mechanism.
Key Points Summary
| Issue | Causes | Solution |
| Lost Messages | ID Corruption, HWM Bound | Check IDs, adjust HWM settings |
| No Response to DEALER | Misconfiguration, Thread Safety | Verify configurations, use socket in one thread |
| Unsynchronized Communication | Improper use of zmq.SNDMORE | Ensure message parts are correctly sent with proper multipart flags |
Conclusion
When a DEALER socket doesn't receive a response from a ROUTER in a ZeroMQ DEALER/ROUTER configuration, the issue typically stems from misconfiguration, misuse of socket options, or thread safety issues. Understanding the intricate behavior of ZeroMQ sockets, along with systematic debugging and configuration review, can usually resolve these issues.
Related reading
- ZeroMQ How to handle non-message-related, asynchronous events in a ZeroMQ node?
- ZeroMQ permanent PULL socket
- ZeroMQ PUB/SUB topology on the same machine
- ZeroMQ round-robin fail-over on disconnected peers
- ZeroMQ with NORM - address already in use error was thrown on 2nd .bind() - why?
- zmq hangs in zmq_proxy() during the cleanup
- ZeroMQ Which socket types for arbitrary communication between exactly 2 peers?
- ZIP file content type for HTTP request

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.