Going Real-,me: How to Build a Streaming API - - PowerPoint PPT Presentation

going real me
SMART_READER_LITE
LIVE PREVIEW

Going Real-,me: How to Build a Streaming API - - PowerPoint PPT Presentation

Going Real-,me: How to Build a Streaming API @rossmason, @muleso= About Me Agenda What the heck is Real-,me APIs The


slide-1
SLIDE 1

Going ¡Real-­‑,me: ¡

How ¡to ¡Build ¡a ¡Streaming ¡API ¡ ¡ @rossmason, ¡@muleso= ¡ ¡ ¡ ¡

slide-2
SLIDE 2

About ¡Me ¡

slide-3
SLIDE 3

Agenda ¡

  • What ¡the ¡heck ¡is ¡Real-­‑,me ¡APIs ¡
  • The ¡technology ¡and ¡trends ¡
  • Demos ¡
slide-4
SLIDE 4

What ¡is ¡real-­‑,me? ¡

  • Real-­‑,me: ¡the ¡ability ¡to ¡react ¡to ¡something ¡as ¡

soon ¡as ¡it ¡happens ¡

  • Web ¡real-­‑,me: ¡Same ¡but ¡slower ¡(about ¡

900ms ¡delay ¡is ¡ok) ¡

slide-5
SLIDE 5

What ¡is ¡a ¡real-­‑,me ¡API? ¡

  • Real-­‑,me ¡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 ¡

slide-6
SLIDE 6

Why ¡Real-­‑,me? ¡

  • User ¡experience: ¡Don’t ¡make ¡people ¡wait ¡
  • Accuracy: ¡Don’t ¡make ¡things ¡wait ¡
  • Because ¡life ¡happen ¡in ¡real-­‑,me ¡

¡

slide-7
SLIDE 7

Why ¡Real-­‑,me? ¡

Speed ¡

slide-8
SLIDE 8

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 ¡wai,ng ¡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 ¡
slide-9
SLIDE 9

Why ¡Real-­‑,me? ¡

Broadcast ¡

slide-10
SLIDE 10

Why ¡Real-­‑,me? ¡

Engagement ¡

slide-11
SLIDE 11

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 ¡connec,on ¡

  • pen ¡– ¡Con,nua,ons ¡can ¡be ¡

used ¡ – Harder ¡to ¡implement ¡durable ¡ connec,ons ¡

slide-12
SLIDE 12

REST ¡or ¡Real-­‑,me? ¡

  • Real-­‑,me ¡APIs ¡are ¡addi,ve ¡to ¡an ¡exis,ng ¡REST ¡
  • r ¡SOAP ¡API ¡
  • Invoca,on ¡seman,cs ¡are ¡different ¡

– Client ¡needs ¡to ¡handle ¡two ¡invoca,on ¡models ¡

  • Real-­‑,me ¡APIs ¡are ¡mostly ¡used ¡to ¡query ¡data ¡

– Usually ¡not ¡to ¡perform ¡CRUD ¡opera,ons ¡

  • Have ¡different ¡SLA ¡and ¡reliability ¡requirements ¡
slide-13
SLIDE 13

REST ¡API ¡

REST ¡or ¡Real-­‑,me? ¡

Resource ¡A ¡ Resource ¡B ¡ Resource ¡C ¡ Streaming ¡API ¡ Transport ¡ Query ¡ Processor ¡ Subscrip,on ¡ Manager ¡ consumer ¡

slide-14
SLIDE 14

Real-­‑,me ¡Technologies ¡

  • Transport ¡

– Comet ¡(HTTP) ¡ – WebSocket ¡(HTTP) ¡

  • Protocols ¡

– With ¡formal ¡pub/sub ¡seman,cs: ¡

  • XMPP ¡
  • Bayeux ¡
  • STOMP ¡

– Ad ¡hoc, ¡ie ¡"subscrip,on" ¡expressed ¡in ¡the ¡request: ¡

  • JSON ¡
  • Push ¡

– PubSubHubbub ¡ – Web ¡Hooks ¡

slide-15
SLIDE 15

Real-­‑,me ¡APIs ¡are ¡real ¡

API ¡ Real-­‑;me ¡technology/protocol ¡ Salesforce ¡ Comet ¡ Facebook ¡ PubSubHubbub ¡ Instagram ¡ Ah ¡Hoc ¡(WebHooks/PubSubHubbub) ¡ Twiier ¡ Ad ¡Hoc ¡(Comet) ¡ PubNub ¡ Ad ¡Hoc ¡ SuperFeedr ¡ XMPP ¡ Pusher ¡ Ad ¡Hoc ¡(WebSockets) ¡

slide-16
SLIDE 16

Real-­‑,me ¡APIs: ¡REST ¡+ ¡JSON ¡or ¡XML ¡

1% ¡of ¡all ¡APIs ¡support ¡real-­‑,me ¡interac,on ¡

source: ¡ProgrammableWeb.com ¡

slide-17
SLIDE 17
  • Stop. ¡Demo ¡,me! ¡
slide-18
SLIDE 18

Demo ¡1: ¡AJAX ¡

Streaming ¡API ¡ Transport ¡ Query ¡ Processor ¡ Subscrip,on ¡ Manager ¡ HTTP ¡Long ¡ Polling ¡ CometD ¡ <None> ¡ hips://github.com/rossmason/mule-­‑streaming-­‑api-­‑demo ¡ ¡

slide-19
SLIDE 19

Demo ¡2: ¡WebSockets ¡

Streaming ¡API ¡ Transport ¡ Query ¡ Processor ¡ Subscrip,on ¡ Manager ¡ WebSocket ¡ JMS ¡ Esper ¡ hips://github.com/rossmason/mule-­‑streaming-­‑api-­‑demo ¡ ¡

slide-20
SLIDE 20

Mule ¡real-­‑,me ¡API ¡support ¡

Technologies ¡

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

3rd ¡Party ¡APIs ¡

  • Salesforce ¡Streaming ¡API ¡
  • Facebook ¡real-­‑,me ¡API ¡
  • Twiier ¡Firehose ¡
  • PubNub ¡
slide-21
SLIDE 21

Real-­‑,me ¡Web ¡SotN ¡

  • S,ll ¡in ¡early ¡adopter ¡territory ¡

– But ¡some ¡major ¡APIs ¡use ¡this ¡approach ¡

  • Limita,ons ¡

– No ¡discovery ¡protocol ¡(i.e. ¡WADL) ¡ – Many ¡different ¡methods ¡

  • Some ¡hampered ¡by ¡older ¡browser ¡technology ¡(i.e. ¡Web ¡

Sockets ¡

slide-22
SLIDE 22

Thank ¡You! ¡

  • Twiier: ¡@rossmason, ¡@muleso= ¡
  • Slides: ¡hip://slideshare.net/rossmason ¡
  • Code: ¡hips://github.com/rossmason/mule-­‑streaming-­‑api-­‑demo ¡ ¡
  • Blog: ¡hip://blogs.muleso=.org ¡
  • We ¡are ¡hiring: ¡hip://muleso=.com.careers ¡ ¡