Home  >  

AMF vs. JSON vs. XML

Author photo
AddThis Social Bookmark Button

The biggest bottle neck in any distributed system - or just about any software - is the streaming data, be it writing and reading data to the hard drive or using application protocols for network communications. This streaming of data, usually called Input/Output (I/O) can kill otherwise performant RIA applications.

There are a lot of things that can be done to reduce the amount of I/O an application requires and these techniques usually follow patterns, which the developer has to recognize and apply with discretion. At this level it’s all about application design - how the application chooses to communicate with other processes be they local or remote. For example, there is the "batch" pattern which says that it is sometimes cheaper to batch many I/O operation than to do them individually. But again using that pattern requires planning and a specific context to make it effective.

Beyond application I/O patterns we must also consider the application protocols themselves. By application protocol I mean anything above the TCP/IP stack which, for the purposes for RIA, includes, parameterized HTTP, XML over HTTP (usually used with REST), SOAP based Web services (pretty much the same as XML over HTTP but, for good or bad, standardize), CORBA IIOP, Java RMI, DCOM, JSON, AMF. These are collectively called Remote Procedure Call (RPC) oriented application protocols. SMTP, POP3, IMAP4, LDAP are examples of other applications protocols.

JSON, developed, by Douglas Crockford, has received a lot of attention and for good reason. Its much more efficient than using XML when you need to exchange complex messages - however simple parameterized HTTP is probably faster for very simple communications.

Action Message Format (AMF), which developed by Adobe and is open to the public, is another RPC format that is gaining momentum among RIA developers. Although AMF is mostly used by Flash and Flex developers there are implementations of this protocol in PHP, Java, and even .NET.

JSON and AMF seem to be far more efficient than XML over HTTP but they also depend on the existence of libraries designed to encode and decode the content. XML on the other hand is supported by all modern languages as XML parsers are included in the base libraries of most RIA platforms (e.g. Flex, Ajax, Silverlight, Curl, Java). In addition, XML is simply easier to understand when looking at an arbitrary web interface.

So there appears to be good uses cases for two categories of RPC protocols in RIA applications: XML for public APIs and Compact Protocols (e.g. JSON and AMF) for private communications.

In the case of public APIs, if you are going to publish a Web API that can be used by any application (e.g. Amazon Web Services, Google Code) than you want provide XML interfaces at the very least. You can also provide JSON and AMF, but XML must be present or adoption won't happen.

In the case of private APIs - those web APIs used by a single RIA application or within the enterprise - you can choose between XML, AMF, JSON or something else. If it’s your application and your not attempting to support public consumption use what ever makes sense to you. In the case of private APIs the use of compact protocols such as JSON and AMF makes a lot of sense. They tend to be much faster in both message size and parsing than XML and provide a significant difference in over all application performance.

The question on my mind is between JSON and AMF, which one will come to dominate the RIA industry? Many platforms play both sides. For example, PHP supports JSON and AMF. But which protocol will become the de facto standard? At this point it’s anyone’s guess. The truth is that performance differences between JSON and AMF are not that wide. A really good analysis of this was done by Patrick Mineault in his 5 1/2 blog a couple of years ago.

Perhaps in the long run there is room enough for both compact protocols and developers can use whichever one makes the most sense for their platform. For example, it’s hard to imagine why Ajax frameworks would support AMF. JSON was specifically designed for JavaScript. At the same time Flex applications will probably use AMF instead of JSON as AMF is the native protocol for Flash players. Developers on other platforms (e.g. JavaFX, Silverlight, Curl) will probably make the choice depending on what their backend best supports. At any rate it will be interesting to see how these compact protocols evolve and which, if any of the two, will come to dominate in the RIA industry. That's not to say that XML over HTTP is going away - not be a long shot. But when developers choose to use a more compact protocol its probably going to be a matter of taste when choosing between AMF and JSON.

Read more from Richard Monson-Haefel. Richard Monson-Haefel's Atom feed

Comments

11 Comments

Wouldn't AMF support in browsers (for javascript) require some sort of socket support or something? At the rate that browsers develop I don't really see this happening anytime soon. Maybe in 20 years when HTML5 is finished!

Isn't it more likely that JSON becomes natively supported in Actionscript?

Radek said:

@Cameron:
AMF itself can be implemented in the browser. Socket will be required only for data push to the browser. You can still have AMF sent through HTTP if you need.

Laurent said:

Yeah, having a JSON implementation natively in Flash would be great.

Johan said:

James Ward developed a nice app called BlazeBench to demonstrate/test AMF/Blaze DS performance compared with JSON and XML

http://www.jamesward.com/wordpress/2007/12/12/blazebench-why-you-want-amf-and-blazeds/

Noah said:

Doesn't AMF requires BlazeDS, which Adobe charges for? I'm asking honestly because I believe the situation has changed a few times and I've been having trouble researching it. Anyway if so that would be another factor in making the choice.
Great article, by the way! Once again another InsideRIA piece directly addressing the real issues developers are dealing with today.

Guillaume Racine said:

BlazeDS is open source, adobe charge for the Live Cycle Data Service which supports more advanced features.

Hi, PHP developers can also use AMF. Zend will integrate AMF support in the zend framework. Great news for the PHP community.

Anil said:

Thanks Richard. Nice and informative !!!

Rudi Louw said:

I'm researching JSON myself at the moment and was wondering why it hasn't caught on yet within any of the companies I've worked for, then I got thinking about the quick and easy implementation of the protocol you want to use, hence the XML's XSD, which does make life a lot easier server side... even if it's a private application, it only takes one "know-it-all" developer to break the schema.

Anyway, I'm still going to give JSON and AMF a test run in a live environment, honestly because it excites me and I want to see it perform. Any pitfalls that anyone know of? Security wise maybe?

anon_anon said:

XML actually doesn't have a performance issue, this article explains this in detail

http://soa.sys-con.com/node/250512

Leave a comment


Tag Cloud

Poll: Mobile Features

What feature do you use most on your mobile phone?

Vote | View Poll Results | Read Related Blog Entry

Latest Features

Recommended for You

@InsideRIA on Twitter

Archives

  • Or, visit our complete archive.  

About This Site

Welcome to the premiere community site for all things RIA sponsored by O'Reilly Media and Adobe Systems Incorporated.