Hacker News new | ask | show | jobs
by Doman 2067 days ago
We are using 0mq for monitoring of electric vehicles fleet. Millions of messages every day (hundreds of GB), zero problems with bad internet connection (common in moving vehicles). Every sent message is received regardless of connectivity issues. Just a little implementation annoyances here and there but it is serving us well since 2015.
1 comments

How does 0mq achieve that? For all I have read and tried to use of it, 0mq explicitly offers no message delivery guarantees, instead relying on your own implementation to achieve them. So, I don't doubt that your system works like you described, but I think you may be overvaluing 0mq's contribution to it.
The ZeroMQ Guide has a chapter dedicated to reliability stuff: https://zguide.zeromq.org/docs/chapter4/

Maybe there is no guarantee, but it can handle unreliable connection just fine, at least when I used it a few years ago.

Yes, I have read the guide pretty thoroughly. What all those things have in common is that they are your responsibility to implement - all that 0mq does is reconnect the socket, and queue up messages. Anything else that could give you reliability is either TCP's problem or yours. That includes timeouts, retransmit, ACKs, keepalives, heartbeats, rate control, message storage, everything that ensures reliability - with 0mq you get to implement it. Lazy pirate indeed.
We implemented KISS state machine based on TCP timeouts and server response.

Pseudocode:

  Send msg to server
    if socket timeout:
      reinit socket and send again
  Recv from server
   if recv.msg != 'ok':
     send again
   else
     remove msg from storage


One message has from few to few hundreds Kilobytes. Messages are stored and sent as custom binary data for better compression (better that protobuffs). ZMQ takes complexity of raw tcp sockets away and this is what we needed it for. As much and as little.
This leaves higher application code to handle duplicated messages. It also does not handle cases where the client connects later than the server send, but would still like to receive the server messages. It also doesn't handle rate control (overwhelming the network).

These may all be fine for your application, and then 0mq is an excellent fit. But I think that for most applications, having some kind of pre-implemebted solution to all of these problems, even with slightly more overhead, is extremely valuable.

> This leaves higher application code to handle duplicated messages.

True, better send twice than never.

> the client connects later than the server send

Server only responds, never sends anything.

> overwhelming the network

"broker" is handling it nicely

I strongly agree that zmq will not fit in every use case. Always search for best option.