This Friday was was hack day at Backcountry.com. During hack day, all the engineers and a few other groups of people are given the freedom to work on any crazy idea they can think of. The result is fantastic innovations engineered at super-speed.
On Backcountry.com, we collect content from our users in the form of product reviews, questions, answers and more. For my team's project, we wanted to allow users to automatically post this content to social networks such as Facebook and Twitter. There are two parts to the project. First, provide users an interface to grant us access their networks (typically via OAuth) and to configure which content they're willing to spam their friends with. Second, when they post the content (reviews, etc.), send it to the social networks per the user's preferences.
Thanks to Josh Braegger and Jon Morrey, we send events to a message queue when users submit content. This allowed us to write a separate daemon that monitors the queue and posts content to social networks asynchronously. If there is a problem posting to Twitter or Facebook is being slow, it won't cause the website to lag at all.
The interface for authenticating with Facebook and Twitter is built into Backcountry.com, which was written in Perl, so I used Net::Twitter. Use of OAuth in this library is considered beta, but we didn't have any problems with it. The non-beta alternative is simple authentication, but Twitter is killing that method this month, so that really wasn't an option. Net::Twitter required us to upgrade Moose which caused a number of problems, but after an hour or so of hacking, things were working.
Authentication for Facebook was more simple than with Twitter due to a slightly diffierent version of OAuth which uses SSL to manage some of the security, making the handshake more simple. I was able to make the SSL requests using LWP without any fancy coding. There isn't any client library to use with Facebook and yet it still required less code to use their API. Props to the Facebook architects.
The second part of the project was to write a daemon that listens to the message queue for content posting events and to post corresponding content to the author's configured social websites. This was done using Java. All of this portion was done by Andres Arias so I can't explain it as well. But Apache MQ was very clean to integrate with and the tokens needed for posting to Facebook and Twitter were embedded in the events. So the Java daemon didn't have to connect to our database for any additional information and was therefore very simple, lightweight and fast.
In the true spirit of Hack Day, the interface wasn't perfect, but to be honest I think it turned out pretty good. Check out this video to see the final product. Thanks to my fantastic project team who made this project so fun and successful: Ben Preston, Kim Sullivan, Andres Arias and Mike Stevens. With luck, we'll see this feature on our production website soon.