Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Adding realtime to your API by Justin Karneges

Adding realtime to your API by Justin Karneges

More Decks by API Strategy & Practice Conference

Other Decks in Technology

Transcript

  1. Adding realtime to your API [email protected] About me 䡧 Fanout

    䡧 Livefyre CTO 䡧 XMPP contributor 䡧 Keywords: realtime, network protocols, federation, open standards
  2. Adding realtime to your API [email protected] Topics 䡧 What is

    a realtime API? 䡧 Challenges 䡧 A new architecture 䡧 Demo
  3. Adding realtime to your API [email protected] What is realtime? 䡧

    “Push” data to recipients 䡧 News, fintech, collaboration, chat, dispatch, games, etc. 䡧 Near-realtime
  4. Adding realtime to your API [email protected] Does my API need

    to be realtime? 䡧 Users expect realtime experiences 䡧 Realtime apps depend on realtime APIs 䡧 Polling sucks 䡧 So…. yes
  5. Adding realtime to your API [email protected] “A Post HTTP World”

    ? 䡧 Don’t worry, most realtime APIs today are HTTP-based. 䡧 There are new protocols, but it’s going to be a long transition. 䡧 Also, HTTP/2 may address most issues.
  6. Adding realtime to your API [email protected] Common realtime push mechanisms

    䡧 HTTP streaming 䡧 HTTP long-polling 䡧 Webhooks (HTTP callbacks) 䡧 WebSockets
  7. Adding realtime to your API [email protected] HTTP streaming 䡧 Response

    with indefinite length 䡧 Content usually line-delimited text 䡧 Usually JSON or Server-Sent Events (SSE)
  8. Adding realtime to your API [email protected] GET /1.1/statuses/sample.json HTTP/1.1
 Host:

    stream.twitter.com
 Authorization: OAuth […] HTTP streaming
  9. Adding realtime to your API [email protected] HTTP/1.1 200 OK connection:

    close content-type: application/json date: Fri, 17 Apr 2015 00:32:07 GMT server: tsa transfer-encoding: chunked x-connection-hash: 6028cbda…6f0443a6 {"created_at":"Fri Apr 17 00:32:06 +0000 2015”,"id": 588862464202297345,”text":"tweet 1", … } {"created_at":"Fri Apr 17 00:32:07 +0000 2015”,"id": 588862468392255488,"text":"tweet 2", … } … HTTP streaming
  10. Adding realtime to your API [email protected] Immature ecosystem 䡧 Most

    tools are end-to-end 䡧 Little interoperability 䡧 Realtime APIs tend to be custom-built
  11. Adding realtime to your API [email protected] Custom-built realtime push 䡧

    Event-driven frameworks 䡧 Complex code 䡧 Separate codebase from the non-realtime parts 䡧 Specific to vendor/application
  12. Adding realtime to your API [email protected] Pull has it right

    Client Client Client Caching / CDN API Management Backend API + directives API
  13. Adding realtime to your API [email protected] Let’s make Push awesome

    as Pull 䡧 Separate API design, engineering, operations 䡧 Interoperable / standardized components 䡧 Reference implementation: Pushpin 䡧 Proxy server with realtime magic 䡧 Open source
  14. Adding realtime to your API [email protected] Generic Realtime Intermediary Protocol

    (GRIP) 䡧 Common protocol between edge and backend 䡧 Engineering targets GRIP 䡧 DevOps manages the edge tier however they want 䡧 Client protocol agnostic
  15. Adding realtime to your API [email protected] GRIP flow Client API

    Server HTTP request HTTP request (forwarded)
  16. Adding realtime to your API [email protected] GRIP flow Client API

    Server HTTP request HTTP request (forwarded) instructions response
  17. Adding realtime to your API [email protected] GRIP flow Client API

    Server HTTP request push payload HTTP response (realtime push)
  18. Adding realtime to your API [email protected] Real world example 䡧

    LaunchDarkly 䡧 Continuous delivery platform 䡧 Feature flags with controlled rollouts 䡧 Feature checks don’t require contact with LaunchDarkly
  19. Adding realtime to your API [email protected] Real world example LD

    Agent API Backend App Client App Server A LaunchDarkly customer’s web service LaunchDarkly API service GET /page config sync (config cache)
  20. Adding realtime to your API [email protected] Example project: TodoMVC 䡧

    http://todomvc.pushpin.org/ 䡧 To-do list demo with realtime collaboration 䡧 Built with React, Pushpin, Django, Redis 䡧 API documented with Apiary
  21. Adding realtime to your API [email protected] Thanks! 䡧 Tell us

    about realtime apps you’re building 䡧 Check out the project:
 http://pushpin.org