I recently blogged about a sample Heroku application that lets you capture Leads from a Facebook application or page. I’d now like to discuss the architecture and some of the technologies I used for that application. You can also download and peruse the application code from GitHub.
The figure on the left gives a high-level overview of the application architecture. It is a Node.js application running on Heroku that uses OAuth to login to Facebook and then inserts Lead records in Salesforce using the Force.com REST API. Here’s some additional color.
- Heroku-Facebook integration: The application is built using the native Heroku-Facebook integration that makes it easy to build Facebook apps in the cloud. Whether you want to build a website that integrates with Facebook, or a ‘native’ Facebook application (aka Canvas application), you need to host your web pages and application logic somewhere. Instead of trying to setup this infrastructure (servers, firewalls, routers etc.) in-house, Heroku lets you leverage the agility, scale and performance of the cloud to host your Facebook applications. And the native Heroku-Facebook integration makes this process even simpler. Once you create a new Facebook application, simply choose Cloud Services–>Heroku to host your application, pick your development language of choice (currently Ruby, Node.js, PHP and Python), enter your email address and you have a production-ready Facebook application running on Heroku in less than a minute. Its like pressing the ‘Easy’ button for developing social apps.
- Socket.io: The app uses the great Socket.io library to establish a two-way communication channel between the server and the browser. Socket.io is a cross-browser implementation of the WebSocket protocol and makes building dynamic web apps in Node.js really simple. The application makes a FQL query on the server to get a list of the user’s Facebook friends (for use in the ‘Refer a Friend’ feature) and then sends the response to the browser via a Socket.io connection. The advantage of this asynchronous design is that the initial landing page for the application can render without waiting for the FQL query to finish. In addition to Socket.io, you can also use services like Pusher to enable real-time push notifications in your Heroku web applications. The equivalent in the Force.com world is of course the Streaming API (now GA!).
If you’re interested in learning more about developing Facebook applications on Heroku that integrate with Salesforce, join us in San Francisco for Cloudstock on March 15th. Pat’s doing a great session focused specifically on building these type of applications and there are many other technical sessions to check out as well. Hope to see you there. Till then, keep the questions and comments coming.