Hydna: a scalable real-time platform

Presentation by Isak Wiström <iw@hydna.com>

To control this slideshow from your iOS or Android phone (through Hydna):
Visit bit.ly/18jEDRL and enter the following code:

0

Slideshow code courtesy of reveal.js.

What is Hydna?

Hydna is a hosted backend into which you can send data and have it instantly appear on other devices.

A hosted ...

  • No servers to setup/maintain
  • Get started in seconds
  • Scalable
  • Focus on your core business

... backend

  1. Transports
  2. Routing
  3. Behaviors

1. Transports

Transports are the different protocols clients can use to communicate with Hydna. The following are currently supported:

WebSockets - Binary TCP - Flash - Comet - HTTP/Push

2. Routing

Routing is the act of accepting data from a sender and delivering it to the intended recipients. Routing works across transports.

  • Domains (e.g. public.hydna.net).
  • Channels (e.g. /chat or /user-32)
  • Modes (r, w, e). Permissions.

3. Behaviors

Behaviors are small snippets of JavaScript that you deploy to Hydna's infrastructure. They are used to instruct Hydna how to behave when clients perform different actions (open channels, emit signals etc).

Authentication, communication with external services, global state etc

What can you do with Hydna?

Hydna is ideal for building dashboards, activity streams, notification- and chat systems, real-time collaboration, live statistics, remote controls, multiplayer games, and more.

Client libraries

Client libraries detect and select best available transport.

JavaScript, Node.js, Erlang, Java, Objective-C, C++

Python, PHP, Ruby, Go etc.

Client libraries - Examples

JavaScript

// open a channel on the domain `public.hydna.net` in read and write mode.
var channel = new HydnaChannel('public.hydna.net/hello-world', 'rw');

// register an event handler that alerts the data-part of messages when
// they are received.
channel.onmessage = function(e) {
    alert(e.data);
};

// send a message immediately when the channel has been opened.
channel.onopen = function() {
    channel.send('Hello there!');
};

Javascript example

Push API

Simple HTTP interface. Limited to sending messages and emitting signals. Does not require a client library. Example using curl:

curl --data "hello world" http://public.hydna.net/hello-push

Push API example

Python (push) lib

Full documentation on GitHub

import hydna

# send a message
hydna.push('public.hydna.net/hello-push', 'test')

# emit a signal
hydna.emit('public.hydna.net/hello-emit', 'test')

Python example

Ruby (push) lib

Full documentation on GitHub

require 'hydna'

# send a message
Hydna.push('public.hydna.net/hello-push', 'test')

# emit a signal
Hydna.emit('public.hydna.net/hello-emit', 'test')

Ruby example

PHP (push) lib

Full documentation on GitHub

require("hydna-push.php");

$hydna = new Hydna(); 

try {
    // send a message
    $hydna->push("http://public.hydna.net/hello-push", "Hello World!");

    // emit a signal
    $hydna->emit("http://public.hydna.net/hello-emit", "Hello World!");

} catch(Exception $e) {
    print $e->getMessage(); 
}

Behaviors - Examples

Simple authentication

behavior('/admin', { 
    open: function(event) {
        if (event.write) {
            // the client requested to write to the channel. let's examine
            // whether the token matches the secret password.
            if (event.token != 'secret password') {
                event.deny('Not allowed to write to channel.');
            } else {
                event.allow('Allowed to write to channel.');
            }
        } else {
            // the client did not request to write, we can allow that
            // without looking at the token.
            event.allow('Allowed to read from channel.');
        }
    }
});

That's it! Now get cracking!

Demo applications / Documentation / Tutorials