Realtime Horse Race Display with Diffusion Cloud’s JSON Topics

Push Technology - June 16, 2016

The latest version of Diffusion Clouds introduces a JSON Topic type that provides an easy to use and efficient mechanism for distributing JSON and binary data. JSON topics enable you to structure your data using JSON. The data is transmitted in a Concise Binary Object Representation (CBOR: binary form for increased efficiency with only the changes to that binary representation being sent over the wire. Another facet of the introduction of the JSON Topic, is the simplification of the APIs required to interact with them compared to previous topic types.

This blog shows the ease with which the JavaScript Unified API can be used to create, update and subscribe to JSON data by use of a specific scenario. The scenario chosen for this blog is the publication and subscription to a realtime feed of race horse position information as a race is taking place and the display of the position of each horse on Google Maps. For the purposes of this blog, the realtime feed is simulated by the reading of a file of JSON records, each representing the position of each horse at 100ms intervals:

{ “T”: “2016-03-05T15:42:40.0Z”, “I”: “3020160305154001”, “X”: -563.587, “Y”: -346.540, “V”: 0.12, “K”: 0 }


T The timestamp for this data event.

I The identifier of the race and race horse.

X The X position of the horse in meters from the finish post.

Y The Y position of the horse in meters from the finish post.

V The velocity of the first horse in meters per second.

K A data format version field.

The data has been provided by Total Performance Data:

Control Client

As with any Diffusion Cloud solution, responsibility for creating the topic and updating it lies with a Control Client, in this case written with the Unified JavaScript API and running in Node.JS. The Control Client connects to Diffusion Cloud, reads the data file into memory and publishes it out in a never ending loop delaying between publishing each line in order to match the live data rate. To build the Control client we follow the following steps:

Step 1) Connect to Diffusion Cloud

Step 2) Within the onConnectSuccess function, create the JSON topic

Once the topic has been successfully created, updates to the topic are initiated.

Step 3) Update the topic

Updating the topic involves creating a content object from a JSON object and updating the topic with that content then delaying for 15ms before sending out the next update so as to match the update rate of the original live data.


The subscribing client is also written against the Unified JavaScript API. The client connects to the Diffusion Cloud server and subscribes to the topic on which the JSON data is published. The subscribe function invokes functions indicating successful subscription to the topic, un-subscription from the topic and update to the data associated with the topic. Unlike previous incarnations of the API, the new Unified Topic API maintains the live topic data on behalf of the client, applying all received deltas to it. The client is presented with the complete data object each time an update is received. The previous version of the data is also provided enabling the calculation of what has changed if required.

Step 1 ) Subscribe to the JSON data and receive a JSON object each time an update is received.

The client now has a native JavaScript object accessed in the normal way, for example, with the JSON objects used in the horse racing scenario, the x position of the horse is jsObj.X and the y position, jsObj.Y.

Step 2) Display the data, as it arrives, as an icon overlaid onto Google Maps.

The cosmologicalConstant is a multiplication factor to better fit the data to the map…

Run the Demo

To run the demo:

  1. Request a Diffusion Cloud instance. You will need to edit the variables at the top of racehorseclient.js to point to your Diffusion Cloud service.
  2. Open the client, html, in a browser.
  3. Start the Control Client by running node horserace.js

The full source for the demo as well as the data file can be found on Github here.

The new JSON topic type provides a highly optimized means of publishing JSON data over the pubic internet and mobile networks accessed by an easy to use API available across multiple languages. The developer works purely with the entire JSON objects, the API hiding all complexity associated with calculating, transmitting and applying deltas.

For more information on the new JSON topic, click here.

Want to see how easy it is to get started with Diffusion Cloud? Sign up for a free demo here.


The Diffusion® Intelligent Event-Data Platform makes it easy to consume, enrich and deliver event-data in real-time across all network conditions. Push Technology pioneered and is the sole provider of real-time delta data streaming™ technology that powers mission-critical business applications worldwide. Leading brands use Push Technology to bring innovative products to market faster by reducing the software development efforts using the low-code features. The Diffusion® Intelligent Event-Data Platform is available on-premise, in-the-cloud, or in a hybrid configuration. Learn how Push Technology can reduce infrastructure costs, and increase speed, efficiency, and reliability, of your web, mobile, and IoT application.

Learn More: View Blog Posts and Developer Resources


Check out these other resources


Info Center

Case Studies, White Papers, and Tech Talk notes relating to Diffusion and the customers benefiting from using it.


Quick Start Guide

Step-by-step guide to getting started fast with Diffusion or Diffusion Cloud.


Diffusion Cloud

Get the facts and the details about our Diffusion Cloud platform.