[zeromq-dev] Messaging patterns background

Martin Sustrik sustrik at 250bpm.com
Tue Apr 5 10:38:20 CEST 2011


Hi all,

It's great we are finally having some serious discussion of the 
messaging patterns!

This mail attempts to give some background to the internal architecture 
of the patterns as currently implemented in 0MQ, so that the discussion 
can proceed in more informed way.

First of all, it should be noted that 0MQ stack is modular in both 
vertical and horizontal way.

Vertical portions of the stack are called "messaging patterns". You can 
think of each pattern as a different protocol on top of TCP/IP layer (or 
IPC or PGM or whatever). See arch1.png

Individual patterns are clearly separated and non-interoperable. Trying 
to connect PUSH socket to SUB socket is in a way same as trying to 
connect a TCP socket to UDP socket.

The business rationale for this separation is that the messaging use 
cases, as seen in the wild, differ widely, and it's impossible to merge 
all of them into a single protocol, unless, of course, you are happy 
with setting up a myriad of parameters just to get a basic thing like 
req/rep running.

The separation is also very beneficial as it prevents the spread of 
contagion: If feature X is introduced to pattern Y, it does not affect 
behaviour of pattern Z in unforeseen ways.

Next, there are two horizontal layers of the stack. There a "common 
infrastructure" layer, that, to put it simply, controls how nodes 
interact with their immediate neighbours and there's "end-to-end" layer 
which controls how applications speak each to another.

For those not familiar with protocol design, end-to-end is a basic 
principle underlying the design of Internet stack. It states that if a 
functionality can be implemented at the endpoints, it should. That 
allows intermediate nodes (routers, switches etc.) to be relatively 
simple. In other words, end-to-end principle can be expressed as "smart 
endpoints, dumb network".

arch2.png shows how TCP/IP suite implements the end-to-end principle. IP 
protocol handles the functionality that's needed at each node, such as 
routing. At the endpoints there can be an end-to-end protocol layered on 
top of IP to provide additional services. Primary example of end-to-end 
protocol is TCP which provides ordering and reliability on top of IP.

In 0MQ the layer equivalent to IP is represented by X- sockets while 
end-to-end layer is represented by non-X sockets.

Thus, in request/reply pattern, there's XREQ and XREP sockets that can 
be used to create the "dumb network" while REQ/REP is layered on top of 
it at the endpoints and can provide smart behaviour, such as message 
resending, droping of duplicates etc. See arch3.png diagram.

It should be noted that the end-to-end principle is the main reason why 
Internet scales. It allows you to put dumb intermediate nodes into the 
network without affecting the end-to-end functionality. For example, if 
you create an application using TCP on two boxes connected using a 
simple crossover cable, you are guaranteed that the same application 
would work even if there are intermediate nodes put into the middle 
(switches, routers, ISPs, satellite connections, Internet backbones, 
etc.) Scalability of 0MQ is achieved using the same principle.

So, when thinking about messaging patterns, before proposing a solution, 
always do a simple mental experiment: Think of how the proposal would 
work if there's an intermediate node added to the topology (arch4.png). 
If the design breaks, it doesn't adhere to the 0MQ scalability model and 
probably needs some rethinking.

Hm, maybe this rant should go to the architeture wiki page?

Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: arch1.png
Type: image/png
Size: 3356 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20110405/cecf635c/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: arch2.png
Type: image/png
Size: 2860 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20110405/cecf635c/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: arch3.png
Type: image/png
Size: 4435 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20110405/cecf635c/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: arch4.png
Type: image/png
Size: 11796 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20110405/cecf635c/attachment-0003.png>


More information about the zeromq-dev mailing list