Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a good thing for a custom rest protocol to be binary based instead of text based like Http?

Have you ever seen a good reason to create a custom binary rest protocol instead of using the basic http rest implementation?

I am currently working on a service oriented architecture framework in .Net responsible for hosting and consuming services. I don't want to be based on an existing framework like Remoting or WCF, because I want total flexibility and control for performing custom optimization.

So here I am trying to find the best protocol for handling this SOA framework. I like the request/response stateless connection nature of REST and the uri for defining resources, but I dislike the text based nature of HTTP.

Here are my arguments for disliking HTTP, correct me if I'm wrong:

  • First an evidence, parsing text is less efficient than parsing binary. I'd prefer a fixed length binary header containing the content length and a binary content.

  • Second, there is no notion of sequence number for http requests, so the only way of associating a response with its request is the socket connection used to send the request and receiving the response. This means there can only be one pending request at a time for a specified socket, so if a service consumer want to send multiple requests in parallel to a service, it need to open multiple socket to the server. A custom rest protocol could define a sequence number for requests, so request and response would be associated with the sequence number instead of the socket and there could be multiple requests sent in parallel on the same socket. I think there is no way to do this standardly with HTTP, it could be done with a custom text based protocol, but why not make it binary based to gain performance.

To add a little more context, my SOA framework does not need to be accessible from a non .Net consumer, so I have no restriction about using the .Net binary formatter or another custom binary formatter.

So am I making any sense for wanting a custom binary rest protocol? If you think I'm wrong please tell me your arguments.

Thanks.

like image 618
Jeff Cyr Avatar asked Dec 18 '22 05:12

Jeff Cyr


2 Answers

REST is an architectural style for constructing web services. Roy Fielding articulated it based on his experience in designing HTTP, but it transcends HTTP. You can deploy a RESTful service over ordinary email exchange for instance.

The REST representations of your resources can be anything you like, though Roy really stresses that people should try to use very carefully designed, standard representations. There's nothing wrong with binary. In fact image representations like JPEG and PNG are binary. Google's Protocol Buffers gives you ways of creating compact binary representations of structured data too.

So the short answer is that you can certainly be RESTful and use binary representations and a home-grown binary substitute for HTTP.

I would actually very strongly recommend you use HTTP for efficiency, though. If you use your own protocol then you lose all the leverage provided by the wonderful HTTP caching infrastructure that stands between your server and its clients. The full client load falls right on your server instead of getting spread out over the intermediate caches.

10/4/2010: In our HTTP-based REST APIs we now support Java Serialized Object and Kryo binary representations in addition to XML, JSON, and XHTML. The Kryo serialization library performs significantly better than the others without requiring any special protocol. Another alternative to cut down on bandwidth is to use HTTP compression along with a textual representation.

like image 136
Jim Ferrans Avatar answered Dec 19 '22 18:12

Jim Ferrans


The data of your packets can be whatever you like; be it XML, Plaintext, JSON, or just a binary format. I see no reason to force any specific one of these on yourself (use whatever is most fitting).

Though, when saying 'binary format', most people hear a fixed format of field-lengths and other really annoying things. Generally, if you aren't desperate from a data-transfer point of view, I see no reason to go this way [though you may do a binary serialisation of .net objects so they can be re-instantiated [or look at the 'protocol buffers' lib for .net]].

Summary: Seems okay to me. Whatever floats your boat.

like image 42
Noon Silk Avatar answered Dec 19 '22 17:12

Noon Silk