Friday, June 8, 2007

Server push and real-time content update

Most web applications in need of displaying frequently refreshed data like stock quotes or traffic and weather information, use polling techniques to achieve the illusion of constantly updated UI. The do this by issuing HTTP requests in a timer of some sort and create the illusion of real-time behavior at the expense of bandwidth and scalability. In this chapter, we will discuss an alternative to polling and focus on HTTP 1.1 and its streaming server push capabilities for developing web applications requiring real-time updates. Server push allows true event driven updates to large number of users in a highly scalable and bandwidth friendly manner since updates are sent only when needed and triggered by trapped events like change in a stock's price or changing traffic pattern on a busy highway. These updates are also much more efficient and suffer from lower latency since these are sent on open sockets without TCP connection initiation overhead and without wasting precious threads on blocking sockets. As a demonstration of these capabilities we will build a basic portfolio management system with support for real time market data for a set of hypothetical stocks, commodities and equity derivatives. Please note that this article is not a tutorial on AJAX or other client side aspects of such a portfolio management system, even though we provide an implementation, the focus is on server side scalability, performance and feasibility of such a system in lieu of thick client and server architectures or dedicated terminals as is usually the case on most trading desks on Wall street and other financial districts.

From client (browser's) perspective, the main vehicle for requesting and subsribing to updates from the server relies on XMLHttpRequest with multipart property set to true and the server responding with a content-type of multipart/x-mixed-replace. This allows the server to send the response with the option to send further updates down the wire as needed. Each such refresh replaces the previous content sent by the server and can be handled by the browser either directly or trapped inside XMLHttpRequest javascript handlers. Listing 2.1 below implements this idea for a fairly simple web page that expects such updates and renders them in a table:(TBD)

The main focus of this article as stated above is creation of a server-side framework for pushing extremely large datasets down the wire as subscribed by the clients in a scalable, reliable and efficient manner with minimum resource overheads. Stay tuned for the server-side update shortly.TBD.

No comments: