Thursday, December 21, 2006

Ajax is the beginning of the end for relational databases

On the web, every page is a text document. The text documents are interpreted and displayed by browsers according to a standard contract – HTML.

The classic client-server programming model works very differently – a Visual Basic application, for example, will contain all manner of binary files and libraries that directly call operating system functions. It’s like writing a new browser for each website!

The choice of model has far-reaching consequences – for example in security, in user interface design, in software distribution, and in application integration. But, surprisingly, one part of the classic model remains – the relational database. Mixing a relational database with online text documents should really not work:

  • Database tables are not documents, so they can’t be referenced by URLs or appear in hyperlinks in a standard way
  • There is no standard file format for database tables, so they can’t be transported in a standard way across HTTP
  • Cacheing models for databases and web servers are inconsistent
  • Relational database best practice is for data normalization, whereas HTML documents are naturally un-normalized and hierarchical
  • Security works differently in the database layer to the web server layer, leading to potential inconsistencies and gaps
  • Systems integration for databases is much more difficult, due to the lack of a common extensible approach to table structures and their transformations
As a workaround, developers borrow old client-server tools like ADO.net and JDBC links in object-oriented code, and mismatch them with the text document. This creates a complicated intermediate layer and doesn’t really address the issues above.

Since the biggest use of relational databases nowadays is to supply HTML documents, their massive take-up is something of a mystery. It’s explained by three factors – they are fast, they are stable, and they haven’t had much competition!

But now some competition is arriving at the low end – Ajax. Ajax offers the ability to look up reference data sources during runtime, which is exactly the function of a relational database. And by using URLs, HTTP, XML and javascript, Ajax overcomes each of the relational database flaws above.

Viewing Ajax as a competitor to a relational database might be unconventional, but it’s revealing. In Ajax, the XML file itself represents the database table. There is less focus on a query language like SQL - DOM javascript carries out the bare minimum, with XSLT transformations filling some gaps – but a lot more focus on getting access to the data via URLs and HTTP and XmlHttpRequest.

Apart from data access, the key advantage of Ajax is that it returns data in the same text document format as HTML. So it can be readily inserted without any intermediate layer – in fact sometimes with pretty much no code, using something like < div src="database.xml" >

Of course, you would never use Ajax to download an XML file with a million rows. But you could do some pre-processing on the server, and return a brief XML results file via Ajax. And this pre-processing step is becoming one of the main functions of relational databases – they are being relegated to storing data and returning query results in XML via HTTP, which his not their natural position.

Recently several groups have extended this approach. On the W3C side, an ambitious attempt to replace lines of javascript code with declarative XML binding has been defined – XForms. Although of great theoretical benefit, XForms is hampered by its lack of adoption by the browser manufacturers. And as a grassroots movement, the Atom Publishing Protocol is seeking to standardize the structure of XML databases. It does not require any browser enhancements and has already attained significant adoption, most notably by Google as the foundation for Gmail, Google Calendar and Google Docs & Spreadsheets.

My contrarian prediction for 2007 is that Ajax will take over from ADO.net and JDBC as the middle ground between web pages and data sources. The Atom Publishing Protocol will become a popular way to manage data sources – taking over even more of the relational database scope.

Relational databases will get decoupled from web application development. They will be increasingly relegated to XML storage and output, plus their traditional role in the declining client-server world. After more than 20 years, this is the start of their demise as the all-conquering database technology.

No comments: