I was promised Event Driven APIs and hoverboards. Where are my hoverboards?
I've been thinking a lot lately about real time fancyness and event driven async programming and how that fits really well with the American consumer mentality. We want exactly what we want, exactly when we want it.
This is also how we consume APIs. I see pollers and timeIntervals set up all over the place to continually ping for new information. How many of us have set up a TTL cache or a background or cron job to feed off twitter search? I know I have. And I always feel a little dirty doing that.
Recently I wrote a node.js gowalla library and I included built in polling for checkins and item activity. All of the lib activity is event driven, but consuming the API is still a timed interval. It made me realize that these companies could increase their efficiency by offering an event driven API.
I'm definitely not the first person to propose this. A google search yields tons of results, mostly failures. I presume they're failures because they are all XML based. (Oh! I went there!) It seems difficult, but I wonder if a simpler approach could yield strong results.
Could it be as simple as registering a RESTful POST back to your domain? You'd have to think about security, like limiting API keys to domains and possibly encoding the data with a key that you've only shared with the client. But something simple like that could cut down total requests dramatically.
If I'm pinging twitter every 5 minutes for a search result that occurs 100 times a day, I've cut my requests to 25%. I'm incurring a little more overhead from initiating the requests, but I think it still works out to less time on the network, plus you are pushing out each bit of data only once, instead of the same 20 tweets over and over again.
I don't expect anything like this to pop up soon, but it sure would be nice. And then I wouldn't have to keep writing the pollers that make me feel guilty.
An exercise for the reader: Let's say the twitter search we are polling has 1 new tweet every 2 seconds, because we searched for Bieber or some slang word that the kids are all about. How could an event driven callback improve efficiency there? Would we need some sort of limit and queueing? Could this actually make the data more accurate?