Real-time APIs

21
Real-time APIs and how to build one @rossmason, @mulesoft

description

The number of real-time APIs on the Web are rising. What are real-time APIs, how are they used? How are they built? This deck and demo was presented at InfoQ in San Francisco Nov 2012.

Transcript of Real-time APIs

Page 1: Real-time APIs

Real-time APIsand how to build one

@rossmason, @mulesoft

Page 2: Real-time APIs

Agenda

• What the heck is Real-time APIs• The technology and trends• Demos

Page 3: Real-time APIs

What is real-time?

• Real-time: the ability to react to something as soon as it happens

• Web real-time: Same but slower (about 900ms delay is ok)

Page 4: Real-time APIs

What is a real-time API?

• Real-time API: Allows an app to only register for events that it is interested in– Give me new customers as they are added– Tell me when the stock price changes– Tell me in 4 weeks to send an email to Bob

Page 5: Real-time APIs

Why Real-time?

• User experience: Don’t make people wait• Accuracy: Don’t make things wait• Because life happen in real-time

Page 6: Real-time APIs

Why Real-time?

Speed

Page 7: Real-time APIs

What do most API consumers do?

• Polling– Make a request every 60 seconds– 61.672% of calls yield no result– New data can be available and waiting for 59.9

seconds– Need to work within the boundaries of API rate

limits • How many calls per hour• Total calls per day• Time between calls

Page 8: Real-time APIs

Why Real-time?

Broadcast

Page 9: Real-time APIs

Why Real-time?

Engagement

Page 10: Real-time APIs

Push vs Streaming

Push (aka WebHooks)• I’ll call you back• Asynchronous• Drawbacks

– Need to have a reply channel setup

– Considered a security risk by some

– Reliability complicated – did the data arrive

Streaming• Keep the line open• Request Response• Drawbacks

– Holds a socket connection open – Continuations can be used

– Harder to implement durable connections

Page 11: Real-time APIs

REST or Real-time?

• Real-time APIs are additive to an existing REST or SOAP API

• Invocation semantics are different– Client needs to handle two invocation models

• Real-time APIs are mostly used to query data– Usually not to perform CRUD operations

• Have different SLA and reliability requirements

Page 12: Real-time APIs

REST API

REST or Real-time?

Resource A Resource B Resource C

Streaming API

Transport

Query Processor

Subscription Manager

consumer

Page 13: Real-time APIs

Real-time Technologies• Transport

– Comet (HTTP)– WebSocket (HTTP)

• Protocols– With formal pub/sub semantics:

• XMPP• Bayeux• STOMP

– Ad hoc, ie "subscription" expressed in the request:• JSON

• Push– PubSubHubbub– Web Hooks

Page 14: Real-time APIs

Real-time APIs are realAPI Real-time technology/protocol

Salesforce Comet

Facebook PubSubHubbub

Instagram Ah Hoc (WebHooks/PubSubHubbub)

Twitter Ad Hoc (Comet)

PubNub Ad Hoc

SuperFeedr XMPP

Pusher Ad Hoc (WebSockets)

Page 15: Real-time APIs

Real-time APIs: REST + JSON or XML

1% of all APIs support real-time interaction

source: ProgrammableWeb.com

Page 16: Real-time APIs

Stop. Demo time!

Page 17: Real-time APIs

Demo 1: AJAX

Streaming API

Transport

Query Processor

Subscription Manager

HTTP Long Polling

CometD

<None>

https://github.com/rossmason/mule-streaming-api-demo

Page 18: Real-time APIs

Demo 2: WebSockets

Streaming API

Transport

Query Processor

Subscription Manager

WebSocket

JMS

Esper

https://github.com/rossmason/mule-streaming-api-demo

Page 19: Real-time APIs

Mule real-time API support

Technologies• CometD• Web Sockets• Ad Hoc• PubSubHubbub• XMPP• STOMP• WebHooks

3rd Party APIs• Salesforce Streaming API• Facebook real-time API• Twitter Firehose• PubNub

Page 20: Real-time APIs

Real-time Web SotN

• Still in early adopter territory– But some major APIs use this approach

• Limitations– No discovery protocol (i.e. WADL)– Many different methods• Some hampered by older browser technology (i.e. Web

Sockets

Page 21: Real-time APIs

Thank You!

• Twitter: @rossmason, @mulesoft

• Slides: http://slideshare.net/rossmason

• Code: https://github.com/rossmason/mule-streaming-api-demo

• Blog: http://blogs.mulesoft.org

• We are hiring: http://mulesoft.com.careers