Slide deck originally delivered 2008/09/23 (Brian Dainton @ Austin on Rails).
The dominant network protocol in use on the Web today is HTTP. As Ruby developers writing RESTful apps, we rarely consider the possibilities that exist outside of this box. This talk will show how you can tap into the power of an alternative, complementary protocol -- XMPP -- to deliver new capabilities in your Rails apps.
1. A Change in Protocol
Exploring XMPP in Ruby
Brian Dainton
brian.dainton@gmail.com
brian@fiveruns.com
twitter.com/bdainton
Certainly, as web developers, the protocol we use most frequently is HTTP.
2. HTTP
HyperText Transfer Protocol
We’re all familiar w/HTTP network chatter picture.
3. HTTP
client server
A client....
Opens a connection
Makes a request
server does some work
Sends a response
And the connection is closed.
Image sources:
http://www.flickr.com/photos/bakelite_phones
http://manalang.com/archives/2004/09/19/the-home-computer-of-2004/
4. XMPP
XML Messages
Persistent Connection
XMPP is proving itself more and more to be a complementary protocol on the web today.
This makes our network chatter picture look quite a bit different:
5. XMPP
client server
A client...
Opens a connection
xml messages are sent back and forth
And then the connection is closed. [click]
This capability to send messages over a persistent connection means that we can do some
really neat things with XMPP that we can't do (or do well, anyway) with HTTP.
6. Announcing
I’m very happy to announce my latest social networking app...
Image source:
http://258marketing.wordpress.com/category/advertising-campaign/
7. Whassap
Like Twitter.
No following.
Polite IM.
Whassap.
Like Twitter, but without following.
New key feature: Whassap IMs you to thank you for setting your status.
8. Whassap
mongrel ejabberd
:3000 :5222
tiamat.local
Here’s the app-level architecture for delivering the Whassap service.
I’ve got a Rails app served by mongrels on port 3000 and an XMPP server (ejabberd)
accepting connections on port 5222.
What does XMPP have to do with IM? We need a history lesson.
9. 1998
1998. Internet boom. Top hits of the day.
Image sources:
http://www.amazon.com/Titanic-Music-Motion-Picture/dp/B0000029YC/ref=sr_1_1?
ie=UTF8&s=music&qid=1222457439&sr=1-1
http://www.amazon.com/Backstreet-Boys-ENHANCED-CD/dp/B00000053X/ref=sr_1_5?
ie=UTF8&s=music&qid=1222457465&sr=1-5
http://www.amazon.com/Come-Over-International-Shania-Twain/dp/B000031VR1/
ref=pd_bbs_sr_2?ie=UTF8&s=music&qid=1222457317&sr=8-2
http://www.amazon.com/Genie-Gets-Wish-Christina-Aguilera/dp/B000IFSGUI/ref=sr_1_26?
ie=UTF8&s=music&qid=1222457523&sr=1-26
http://www.amazon.com/Lets-Talk-About-Love-Celine/dp/B000002C4J/ref=sr_1_1?
ie=UTF8&s=music&qid=1222457564&sr=1-1
http://www.amazon.com/Baby-More-Time-Britney-Spears/dp/B00009YNG9/ref=sr_1_2?
ie=UTF8&s=music&qid=1222457593&sr=1-2
10. Jabber
1998
We were also Instant Messaging our friends and work colleagues.
There were problems. Vendor lock-in. No cross-protocol communication.
This sucked.
Enter Jabber.
Image sources:
http://webmessenger.msn.com/
http://www.icq.com/
http://www.makeuseof.com/wp-content/uploads/2008/06/aim_logo.jpeg
http://www.intuitive.com/blog/images/goofy-yahoo-logo.gif
11. Jabber
jabberd
protocol
Jabber Project focused on creating an open platform for instant messaging.
Jabber protocol would later for the basis for...
Image source:
http://florianjensen.com/2008/02/11/jabber-and-data-portability/
12. XMPP
Extensible Messaging
and
Presence Protocol
XMPP.
14. XMPP
Extensible Messaging
and
Presence Protocol
Presence info: available, offline, in a meeting, etc.
15. XMPP
Extensible Messaging
and
Presence Protocol
XML: inherently extensible.
Indeed, there have been many many extensions both proposed and accepted to the XMPP
spec.
16. XMPP
Core IM
VoIP
Embedded Images & Video
Multi-user Chat
The core IM functions comprise ‘XMPP-Core’, but there are a wide range of extensions today.
Ok, back to the present...
18. JIDs
brian@tiamat.local
brian@tiamat.local/iphone
resource
JIDs are a lot like email addresses. XMPP addressing.
Resources allow you to make a device/location-specific distinction.
19. Gems
xmpp4r-simple
xmpp4r
Useful gems:
xmpp4r-simple is feature-poor but dirt simple to use.
xmpp4r, by contrast, is NOT SIMPLE but is incredibly feature-rich.
21. Gems
xmpp4r-simple
xmpp4r
The simple gem was written by Blaine Cook, former chief architect at Twitter. If you’re doing
basic IM over XMPP stuff, use his gem.
Image sources:
http://cache.valleywag.com/assets/resources/2008/05/BlaineCook.jpg
http://photos.igougo.com/pictures-photos-j14184-c4-s2-p61061-Shark_Attack.html
24. Whassap
REST API
So, after a few weeks in production, Whassap starts to get a small -- but excited and loyal --
userbase. The begin to take advantage of the Whassap REST API to poll for updates.
(demo whassap_rest_client w/httparty)
Things are good. REST is awesome; we should all be designing and writing our apps
RESTfully.
Image sources:
http://www.chelseapies.tv/2008/01/hold_the_press_its_wigan_away.html
http://www.healingwithnutrition.com/vitamin.html
25. Whassap
mongrel ejabberd
status bot
tiamat.local
Clearly I've got traction with Whassap. It's time to offer a new service: the capability to
submit Whassap statuses via IM.
Introducing the Whassap Status Bot.
(demo Whassap XMPP Status Bot; show status submission via IM, which uses the REST API to
actually submit the status, same resulting IM)
27. Whassap
The Whassap Facebook app hits the scene. Third-party services propagate Whassap statuses
to Twitter and Pownce. FriendFeed (social content aggregator) starts polling for Whassap
updates.
28. Whassap
mongrel ejabberd
status bot
tiamat.local
(server on fire)
Another recent talk on this XMPP topic (given at OSCON this year)...
29. ...likened REST to Newtonian physics; the analogy is accurate.
REST APIs work great for a long while, but break down in extremely high-scale environments.
Sources:
http://www.slideshare.net
Referenced slide copyright Evan Henshaw-Plath (ENTP.com), Kellan Elliot-McCrea (Flickr.com)
30. Social Web
Apps in the middle of the social web are getting slammed.
- there are 10-20 new Twitter statuses added every second
- there are 60 new photos uploaded to Flickr every second
And those are *just* the POSTs. API polling traffic is order of magnitudes higher.
(demo the GETs)
Image source:
http://code.google.com/apis/socialgraph/
31. The Situation
many clients
interested in specific topic
topic update interval: unknown
data freshness: important
What we've got is a situation where:
- many, many clients are interested to know when
- information on a specific topic (my Whassap status, for example) has been updated
- we can’t make any assumptions about *when* the topic will be updated
- and timeliness of the information is important
32. XMPP PubSub
Publish/Subscribe
Enter XMPP PubSub.
The concept of the publish/subscribe model is nothing new.
With XMPP, though, things operate a bit differently because of the persistent connection.
33. XMPP PubSub
XMPP PubSub Nodes
brian@tiamat.local
Whassap Status
Location
Blog
noah@tiamat.local
Whassap Status
Location
The XMPP PubSub spec: collection of nodes for each JID.
Permissions-based controls for who can publish/subscribe.
Published data is immediately available to a subscriber, manifests itself as a message from
the pubsub service to the subscriber.
To handle merely single personal updates, a simpler, pared-down spec was created...
34. PEP
Personal Eventing
via PubSub
*Personal Eventing* via PubSub.
35. PEP
XMPP PubSub Nodes
brian@tiamat.local
Whassap Status
Location
Blog
noah@tiamat.local
Whassap Status
Location
It constrains the set of nodes to JUST 1 node per Jabber ID.
Users may ONLY publish to their own nodes.
But...users may subscribe to anyone else’s node. This is basically Twitter via XMPP.
36. I've forked xmpp4r-simple it on github to add some PEP support.
(demo pep publisher. intermittently subscribe some other users)
Benefits: no incessant polling, and we get the updates that we want as soon as they exist.
Cool.
When you extrapolate this to the non-Newtonian scale, the savings in bandwidth and CPU
usage are incredible.
38. Federation
juliet@capulet.org
romeo@montegue.net
Concept of open federation is baked directly into the core of XMPP servers.
The analog here is with email.
One server knows how to communicate with the other. The net result is a distributed, but
federated, userbase.
40. For a while, Twitter made its user updates available via XMPP PubSub.
Stamen firehose (now defunct)
Source:
http://www.tom-carden.co.uk/2008/05/16/firehose/
41. A few select services gained access to the Twitter firehose. FriendFeed and Summize (later
became Twitter Search).
A new service has access to the Twitter firehose as well: Gnip.
Image sources:
http://www.friendfeed.com
http://search.twitter.com
http://www.gnipcentral.com/
42. Twitter Twitterrific
Whassap Whassaperrific
Facebook CampTweet
FriendFeed Gnip FriendFeed
Flickr TweetDeck
Digg Twinkle
LinkedIn Custom Client
Gnip sits in the middle between Data Publishers (like Twitter and...Whassap) and Data
Consumers like you and me (and other social aggregator services like FriendFeed, for
example).
They accept data however it is produced and allow users to consume data however they want.
Big benefits for both producers (reduced load) and consumers (reduced/removed throttling,
flexible access methods).
Image source:
http://www.gnipcentral.com/
45. HTTP
+
XMPP
Thanks
The bigger picture:
- the web is evolving, so developer demands are changing
- HTTP is no longer the end-all and be-all for creating webapps today
Add XMPP to your bag of tricks and you’ll be far more ready to tackle some of today’s hardest
problems.
Image sources:
http://code.google.com/apis/socialgraph/
http://inbabble.com/2008/01/27/interview-what-is-the-greatest-challenge-in-mobile-
today/