Polling: It's Good Enough for the WWW & It's Good Enough for You

http://jlsuttles.github.io/push-vs-poll-talk/slides.html

Jessica Lynn Suttles

@jlsuttles

jlsuttles.com

Santa Monica, CA

G5 (Search Marketing)

@g5platform

http://getg5.com

Bend, OR

Mr. Managerâ„¢ Shane Becker

@veganstraightedge

iamshane.com

Steve Klabnik

@steveklabnik

steveklabnik.com

The Farmhouse Podcast

Push vs "Pull"

Shane Becker & Steve Klabnik

http://farmhouse.la/podcast/2

Polling: It's Good Enough for the WWW & It's Good Enough for You

Words are hard.

Words are difficult.

Words are confusing.

So let's start with some definitions.

Push is a style of communication where the request for a given transaction is initiated by the publisher of data.

Pull is a style of communication where the request for a given transaction is initiated by the consumer of data.

Push & pull are antonyms.

Push & pull indicate direction of communication.

Polling is a style of communication where multiple pulls are used to sample server state at an interval.

Polling indicates a continual process that makes use of multiple pulls.

Historically if two components needed to talk on a system they used polling.

So when it came time to design the web it was natural to use a polling model.

And so the web was built on the client-server model.

This model assigns one of two roles to the computers in a network: Client or Server.

A server is a computer system that selectively shares its resources.

A client is a computer or computer program that initiates contact with a server in order to make use of a resource.

The web is one of the largest and most successful software projects, so there must be something to this model.

But lately people have been moving to a push model.

Push feels natural, but it can be expensive.

Expense can refer to server requests or server resources.

Push requests scale linearly.

When using push the server needs to initiate one request per client.

One request per client requires a lot of server resources.

Let's imagine @jlsuttles & @ashedryden each have 100 Twitter followers.

Wow @jlsuttles is giving a great talk right now!

Thank you, @ashedryden! You're too kind. <3 I can't wait for your keynote tomorrow!

.@jlsuttles me neither! It's at 9am sharp. Don't be late!

Push requires a minimum of 300 requests.

That's a lot of requests! Imagine if we had 1,000,000 Twitter followers.

An advantage of push is that it can seem instantaneous.

But the more push requests that need to be sent, the harder it is to make them all seem instantaneous.

Polling can scale better than linear.*

Wow @jlsuttles is giving a great talk right now!

Thank you, @ashedryden! You're too kind. <3 I can't wait for your keynote tomorrow!

.@jlsuttles me neither! It's at 9am sharp. Don't be late!

Polling requires the server to respond to a minimum of 0 requests.

After the tweets have been sent, if all 200 twitter followers open their twitter clients, then its at most 200 requests.

Pull requests are cheap so it's easy to do many at the same time.

*Polling without server side caching can be very expensive.

HTTP Conditional Get

The server sends a Last-Modified header.

The client sends a If-Modified-Since header.

If the server has new data it sends back a 200 OK response code and data.

If the server doesn't have new data it sends back a 304 Not Modified response code and no data.

Memcache

Every pull request hits the cache every time, so no one is ever hitting the server.

The server effectively pushes to the cache to update it, which is inexpensive because the server is guaranteed to have only one client: the cache.

Error Handling

Relying soley on push requires the server to keep track of failures and retries for all subscribers.

It is much more reasonable and less complex for a client to keep track of their own failures and retries.

You don't have to choose just push or just polling.

PubSubHubBub

A subscriber initially pulls a feed from a publisher.

If the feed references a hub, the subscriber can subscribe to the feed on the hub.

Publishers post notifications to the hub whenever they publish something.

The hub then directly notifies the subscriber when the feed is updated.

So the publisher notifies the hub, then the hub notifies the subscriber.

The hub is expensive, but all of the publishers aren't expensive.

OStatus is a microblogging protocol that is built on top of PubHubSubBub

rstat.us is an open source project that uses OStatus.

Is push ever necessary?

Push is necessary when you need low latency updates with high frequency.

Chat

Campfire uses polling with a 2 second interval.

Multiplayer Interactive Games

Chess doesn't need push. First person shooters probably need push.

Polling is the sound engineering decision.

Push a new and interesting solution.

If you're a startup you are probably doing new and exciting things!

It is entirely possible there are applications that need push that we don't know about yet.

But make sure you really need it because if your startup succeeds its going to be pricey to scale.

Thank you!

<3 @jlsuttles

#

/