I have another argument with a friend of mine.
Consider having a need to design a simplistic JSON-based protocol, which is basically used to send sort of events (messages) between parties.
Say, something like
{ event_id: 1, chat_message: "Hello" }
{ event_id: 2, group_id: 3, presence: "online" }
...
I propose to keep this protocol just like above, while my friend proposes to do something like:
{ event_id: 1, details: { chat_message: "Hello" } }
{ event_id: 2, group_id: 3, details: { presence: "online" } }
...
His argument is that just like TCP and, say, HTTP are at different layers of "responsibility", this protocol should use "details" sub-object in order to keep data separated.
Another argument he has is that handlers that handle matched event, should not know anything about "routing" information (things like event_id).
My arguments are:
- We're increasing length of each message (and network traffic, this might be important for a system that exchanges with a lot of messages) for the sake of hiding this information from handlers
Handlers do actually need to know "routing" information, say, to answer them properly:
this.replyTo(event['event_id'], reply); // or... this.replyTo(event, reply);
Even if we'll need to hide event_id and stuff like that from handlers, we can just strip them out before passing to handlers and thus still save on traffic
This protocol is quite simple and is not supposed to be used by anybody else.
What do you think?