DataSync

A real-time feed management system that enables the rapid broadcasting of headlines
for applications in social news, TV, music, sports, commerce and finance.

<!-- EMBED CODE FOR VIEWER -->
<script src="http://cdn.pubnub.com/pubnub.min.js"></script>
<script src="http://cdn.pubnub.com/pubnub-crypto.min.js"></script>
<script src="http://pubnub.github.io/bootstrap-content-curator/dist/js/pubnub-sync.js"></script>
<script>(function(){
    var settings = {
        subscribe_key : 'sub-459a5e4a-9de6-11e0-982f-efe715a9b6b8'
    ,   cipher_key    : 'ODgwNDsmIzczMDustKOiJiM4NzM0O7aqSDNh2mig'
    ,   ssl           : true
    };

    var db = PUBNUB.sync( 'db-public', settings );

    db.all(function(item){       /* -- render all items -- */ });
    db.on.create(function(item){ /* -- render new item  -- */ });
    db.on.update(function(item){ /* -- update item      -- */ });
    db.on.delete(function(item){ /* -- remove item      -- */ });
})();</script>

1. Reporter  


Write a text headline then press "Submit" or press Enter. This will send your headlines to the editor for Publishing and Editing.

How DataSync Works in the Source Code

By pressing submit, you've just done something very powerful. Many synchronous steps execute, placing an amazing new DataSync capability at your fingertips faster than ever before. When you press the submit button, the code will execute as follows:

var item = db.create({ headline : "..." })

and therefore write a new db row entry onto the Editor Database. Next the editor will update the entry as needed:

item.update({ headline : "..." })

Both db.create() and item.update() will save the changes in memory, on your local disk and to the cloud all at the same time. Once you re-connect to the database, any untransmitted changes are sent to the device to sync data in real-time.

Finally to publish simply write to a second DB, a public facing DB, that can be used for read-only updates.

db2.create({ headline : item.headline })

That's it for now with the intro tutorial. To learn more continue down this document for further reading.

2. Editor  

3. Viewer    

 DataSync

Dropbox for your apps data powered by PubNub the worlds largest global Real-time Network. All changes are pushed directly to the app via an always-on Socket Connection in real-time as changes are made.

DataSync is the ability to have apps always be at the same-state regardless of point-of-load. Upon reconnect, all data is re-synced with the client app. Your data is replicated to all data centers and optionally encrypted.

 Real-time Network

Highly Available Global Real-time Network is mandatory for distributed consumers in order to provide a fast and reliable user experience. You can only get that fast "Snappy" feel with a Global Real-time Network.

Every event is replicated more than 500 times; extreme global reliability via a Real-time Network.

 Highly Secure

Security is a complex and widely growing requirement especially for Real-time Mobile and Web Messaging Systems like PubNub. SSL TLS Sockets, SHA256 Message Signing, PAM ACL Access Management and AES256 Symmetric Crypto are industry standard methods for providing High Levels of security for your application.

PubNub provides a default baseline level of security, with optional High Security with industry standard solutions for Signaling and DataSync applications.

Real-time DataSync, for real. See for yourself.

Guaranteed DataSync to Mobile and Web Clients Dramatically simplifies app development. Schema-less NoSQL offers easy data entry without hindering productivity.

Fastest Global Sync Delivery Speed. It'll blow your socks off.

Up to 15ms Sync Delivery Speeds. PubNub announces JavaScript DataSync SDK. Many customers are using DataSync today on the PubNub Real-time Network. We made it even easier by offering an SDK enabling true DataSync powered by the worlds largest Global Real-time Network.

Auto Catch-up after Dropped Connection. Zero Loss.

High speed reconnection times allow recovery of lost data in a snap. After a successful reconnect all pending read/write events are sync'ed.

Documentation for Real-time DataSync SDK

The following is documentation for a Real-time Network DataSync System built for optimal performance on mobile connections and unreliable environments. Because of the full resiliency and high availability of the network, you can always have certainty your data is sync'ed. This SDK docs will describe API usage and considerations when invoking each method provided.

  Initiate DB Connection   PUBNUB.sync()

var settings = {
    publish_key   : 'pub-5ad63a7a-0c72-4b86-978d-960dcdb971e1'
,   subscribe_key : 'sub-459a5e4a-9de6-11e0-982f-efe715a9b6b8'
,   secret_key    : 'sec-fa847381-dcdb-4bcf-a8aa-7b812c390441'
,   cipher_key    : 'ODgwNDsmIzczMDustKOiJiM4NzM0O7aqSDNh2mig'
,   ssl           : true
};

var db = PUBNUB.sync( 'db_name', settings );

  DataSync starts with an always-on Socket Connection

You'll need some API Keys to play with. Start by following these easy steps:

Step Action to Take
1 Signup For PubNub - Signup/Login to PubNub Admin Portal

Optionally Watch PubNub Basic Video 1 - Registering for PubNub API Keys
The video also describes what each key purpose.

2 Paste in your API Keys and run PUBNUB.sync(...)

  Insert New Item   db.create({})

var item = db.create({ headline : "my header text" });
console.log(item.id);

  Write Data Now you are connected to a DataSync DB

This code step is simple and allows you to create a new row in the Sync DB. This process will simultaneously write a new entry in three paths: Local Memory, Local Disk and Cloud. The Cloud path will replicate each write event over 500 times for extreme reliability on a Global Real-time Network.

  Read/Find Items in DB   db.read(id), db.find({}) and db.all()

// option 1 - get one item in DB
var item = db.read(id);
console.log(item);

// option 2 - find items in DB
var items = db.find({ headline : "match" });
console.log(items);

// option 3 - print all items in DB
var items = db.all(function(item){
    console.log(item);
});

  Read Data from a DataSync Database

To read an item, you can specify the ID or search for rows that matchs a key entry in the row.

  Update and Replace Items   item.update({})

// option 1
item.update({ headline : "some updated value" });
console.log(item);

// option 2
db.update( item.id, { headline : "some updated value" } );
console.log(item);

  Make Changes to Rows or Append new Colomns

You have two options to make it easy to change items by executing an instance method on the item directly via item.update({}) or if you know the ID of the item then you can execute db.update( id, {} ) via the DataSync DB instance.

  Delete Items Forever   item.delete()

// option 1
item.delete();

// option 2
db.delete(item.id);

  Delete Items

You have two options to delete items by executing an instance method on the item directly via item.delete() with no arguments specified, or if you know the ID of the item then you can execute db.delete(id) via the DataSync DB instance.

Listen for Real-time DataSync Events

You'll need a way to monitor and act upon changes that occur remotely or on catch-up phases. The best way to do this is by registering an event listener on the events in which you find the most interesting to monitor in real-time.

  OnCreate db.on.create()

db.on.create(function(item){
    console.log(item);
});

  Create Event

When a new inster event is triggered, whether locally or remotely, this callback will be fired for you.

  OnUpdate db.on.update()

db.on.update(function(item){
    console.log(item);
});

  Update Event

When an item changes, whether locally or remotely, you can catch the changes by supplying your callback for the db.on.update() callback register.

  OnDelete db.on.delete()

db.on.delete(function(item){
    console.log(item);
});

  Delete Event

The Delete Event is fired and executes the callback function you provide. The item argument is the full item row that has been deleted.

Server-side APIs for Real-time DataSync

Due to the difficulty to cope with the kind of volumes of data we need to broadcast real-time while keeping a reliable service, using the services of PubNub Real-time Network to stream real-time data is needed. PubNub Real-time Nework provides SDKs in various languages: http://www.pubnub.com/developers.

Python Usage

from Pubnub import Pubnub
import uuid

## Initiate Class
pubnub = Pubnub(
    publish_key=publish_key,
    subscribe_key=subscribe_key,
    secret_key=secret_key,
    cipher_key=cipher_key,
    ssl_on=ssl_on
)

## Create
item_id = str(uuid.uuid4())
info = pubnub.publish({
    'channel' : 'db-public',
    'message' : {
        'id'      : item_id,
        'domain'  : 'server',
        'command' : 'create',
        'data'    : {'headline':'sample'}
    }
})
print(info)

## Update
info = pubnub.publish({
    'channel' : 'db-public',
    'message' : {
        'id'      : item_id,
        'domain'  : 'server',
        'command' : 'update',
        'data'    : {'headline':'updated!'}
    }
})
print(info)

## Delete
info = pubnub.publish({
    'channel' : 'db-public',
    'message' : {
        'id'      : item_id,
        'domain'  : 'server',
        'command' : 'delete'
    }
})
print(info)

Python Setup

sudo pip install pubnub

PHP Usage


<?php
require_once('Pubnub.php');

$pubnub = new Pubnub(
    $publish_key,
    $subscribe_key,
    $secret_key,
    $cipher_key,
    $ssl_on
);

## Create Row
$item_id = uuid();
$pubnub->publish(array(
    'channel' => 'testChannel',
    'message' => array(
        'id'      => $item_id,
        'domain'  => 'server',
        'command' => 'create',
        'data'    => array( 'headline' => 'sample' )
    )
));

## Update Row
$pubnub->publish(array(
    'channel' => 'testChannel',
    'message' => array(
        'id'      => $item_id,
        'domain'  => 'server',
        'command' => 'update',
        'data'    => array( 'headline' => 'updated!' )
    )
));

## Delete Row
$pubnub->publish(array(
    'channel' => 'testChannel',
    'message' => array(
        'id'      => $item_id,
        'domain'  => 'server',
        'command' => 'delete'
    )
));

function uuid() {
    if (function_exists('com_create_guid') === true) {
        return trim(com_create_guid(), '{}');
    }
    return sprintf( '%04X%04X-%04X-%04X-%04X-%04X%04X%04X',
        mt_rand(0, 65535),
        mt_rand(0, 65535),
        mt_rand(0, 65535),
        mt_rand(16384, 20479),
        mt_rand(32768, 49151),
        mt_rand(0, 65535),
        mt_rand(0, 65535),
        mt_rand(0, 65535)
    );
}
?>

PHP Setup

Grab the files from GitHub: PubNub PHP Libraries

curl https://raw.github.com/pubnub/php/master/3.4/PubnubAES.php > PubnubAES.php
curl https://raw.github.com/pubnub/php/master/3.4/Pubnub.php > Pubnub.php

This app: created and maintained by PubNub and Stephen Blum.