The Cheap or Nasty Pattern
There is a general lesson Iâve learned over a couple of decades of writing protocols small and large. I call this the âCheap or Nastyâ pattern: you can often split your work into two aspects or layers, and solve these separatelyâone using a âcheapâ approach, the other using a ânastyâ approach.
The key insight to making Cheap or Nasty work is to realize that many protocols mix a low-volume chatty part for control, and a high-volume asynchronous part for data. For instance, HTTP has a chatty dialog to authenticate and get pages, and an asynchronous dialog to stream data. FTP actually splits this over two ports; one port for control and one port for data.
Protocol designers who donât separate control from data tend to make horrid protocols, because the trade-offs in the two cases are almost totally opposed. What is perfect for control is bad for data, and whatâs ideal for data just doesnât work for control. This is especially true when we want high performance at the same time as extensibility and good error checking.
Letâs break this down using a classic client/server use case. The client connects to the server and authenticates. It then asks for some resource. The server chats back, then starts to send data back to the client. Eventually, the client disconnects or the server finishes, and the conversation is over.
Now, before starting to design these messages, stop and think, and letâs compare the control dialog and the data flow: ...
Get ZeroMQ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.