Cloning Internet Applications with Ruby
We stand on the shoulders of giants. This has been true since the time of Newton (and
even before) and it is certainly true now. Much of what we know and learn of
programming, we learnt from the pioneering programmers before us and what we leave
behind to future generations of programmers is our hard-earned experience and precious
knowledge. This book is all about being the scaffolding upon which the next generation
of programmers stands when they build the next Sistine Chapel of software.
There are many ways that we can build this scaffolding but one of the best ways is simply
to copy from what works. Many programming books attempt to teach with code samples
that the readers can reproduce and try it out themselves. This book goes beyond code
samples. The reader doesn’t only copy snippets of code or build simple applications but
have a chance to take a peek at how a few of the most popular Internet applications today
can possibly be built. We explore how these applications are coded and also the rationale
behind the way they are designed. The aim is to guide the programmer through the steps
of building clones of the various popular Internet applications.
What This Book Covers
Chapter 1, Cloning Internet Applications gives a brief description of the purpose of the
book, the target readers of the book, and a list of the four popular Internet applications we
will be cloning in the subsequent chapters. The bulk of this chapter gives a brief rundown
on the various technologies we will be using to build those clones.
Chapter 2, URL Shorteners – Cloning TinyURL explains about the first popular Internet
application that we investigate and clone in the book, which is TinyURL. This chapter
describes how to create a TinyURL clone, its basic principles, and algorithms used
Chapter 3, Microblogs – Cloning Twitter. The clone in this chapter emulates one of the
hottest and most popular Internet web applications now—Twitter. It describes the basic
principles of a microblogging application and explains how to recreate a feature-complete
Chapter 4, Photo -sharing – Cloning Flickr. Flickr is one of the most popular and
enduring photo-sharing applications on the Internet. This chapter describes how the
reader can re-create a feature complete photo-sharing application the simplest way
possible, following the interface and style in Flickr.
Chapter 5, Social Networking Services – Cloning Facebook 1. The final two chapters
describe the various aspects of Internet social networking services, focusing on one of the
most popular out there now—Facebook. These two chapters also describe the minimal
features of a social networking service and show the reader how to implement these
features in a complete step-by-step guide. The first part is described in this chapter, which
sets the groundwork for the clone and proceeds to describe the data model used in the
Chapter 6, Social Networking Services – Cloning Facebook 2. The final chapter is part
two in describing how to create a Facebook clone. This chapter follows on the previous
chapter and describes the application flow of the Facebook clone we started earlier.
Social Networking Services – Cloning Facebook 1
One of the most dominant Internet services today is the social networking service.
According to a report by the Nielsen Company, in January 2010, the amount of time
an average person spent on Facebook is more than seven hours per month, which
amounts to more than 14 minutes per day. If you lump together the time spent
on Google, Yahoo!, YouTube, Bing, Wikipedia, and Amazon, it still doesn’t beat
Facebook! By March 2010, Facebook accounted for more than seven percent of all
Internet traffic in the United States, surpassing visits to Google. Social networking
services have risen in the past few years to be more than just a passing fad, to be an
important communications tool as well as a part of daily life.
We will be building our last and most complex clone based on Facebook, the most
popular social networking service as of date. The clone we will build here will
be described over this and the next chapter. In this chapter we will cover basic
information about social networking services, main features of the clone that we will
build, as well as the description of the data model we will be using for the clone.
All about social networking services
A social networking service is an Internet service that models social relationships
among people. Essentially it consists of a user profile, his or her social links, and
a variety of additional services. Most social networking services are web-based
and provide various ways for users to interact over the Internet, including sharing
content and communications.
Early social networking websites started in the form of generalized online
communities such as The WELL (1985), theglobe.com (1994), GeoCities (1994), and
Tripod (1995). These early communities focused on communications through chat
rooms, and sharing personal information and topics via simple publishing tools.
Other communities took the approach of simply having people link to each other
via e-mail addresses. These sites in cluded Classmates (1995), focusing on ties with
former schoolmates, and SixDegrees (1997), focusing on indirect ties.
SixDegrees.com in a way was the first to bring together the first few defining features
of a social networking service. The basic features of the first online social networking
services include user profiles, adding friends to a friends list, and sending private
messages. Unfortunately, SixDegrees was too advanced for its time and eventually
closed in 2001.
Interestingly the most popular social networking service in Korea, CyWorld, was
started around this time in 1999. The original intention for CyWorld was to develop
an online dating service similar to Match and provide an open public meeting place
for users to meet online. In 2001, CyWorld launched the minihompy service, a
feature that allows each user to create a virtual homepage. This was highly successful
as celebrities and politicians took to this platform to reach out to their fans and
audience. CyWorld also eventually included a virtual currency called “dottori” in
2002 and a mobile version in 2004. Up to 2008, CyWorld had more than one third of
Korea’s entire population as members with a strong penetration of ninety percent in
the young adults market.
Between 2002 and 2004, a few social networking services became highly popular.
Friendster, started by Jon Abraham in 2002 to compete with Match .com , was highly
successful initially. However due to platform and scalability issues, its popularity
plummeted as newer social networking services were launched. MySpace ,
launched in 2003, was started as a Friendster alternative and became popular with
independent rock bands from Los Angeles as promoters used the platform to
advertise VIP passes for popular clubs. Subsequently, MySpac e facilitated a two-way
conversation between bands and their fans, and music became the growth engine of
MySpace. MySpace also introduced the concept of allowing users to personalize
their pages and to generate unique layouts and backgrounds. Eventually MySpace
became the most dominant social networking service in U.S. until Facebook took
over in 2009.
Mixiis the largest online social networking service in Japan with a total of 20 million
users to date and over ninety percent of users being Japanese. Launched in February
2004 by founder KenjiKasahara, the focus of Mixiis to enable users to meet new
people who share common interests. An interesting feature of Mixi(counterintuitive)
is that it’s an invitation by friend social network, which means that a new user can
only join Mixithrough an invitation by an existing user. This feature is only found
in niche and private social networks such as http://www.asmallworld.net, a
successful social networking service that caters to celebrities and high net worth
individuals. This invitation-based model holds the user responsible for who they
invite, and thus reduces unwanted behavior within the network, refl ecting Japanese
Social networking began to emerge as a part of business Internet strategy at around
2005 when Yahoo! launched Yahoo! 360 , its first attempt at a social networking
service. In July 2005 News Corporation bought MySpace. It was around this time as
well that the first mainland Chinese social networks started. The three most notable
examples in chronological order are 51.com (2005), Xiaonei(2005), and Kaixin001
(2008). 51.com drew its inspiration from CyWorld, and later MySpace and QQ. On
the other hand, Xiaoneihas a user interface that follows Facebook, though it also
offers the user flexibility to change the look and feel, similar to MySpace. Kaixin001,
the latest social networking platform in China with the fastest growing number of
users, started in 2008 and the platform and user interface are remarkably similar
It was also around this time that more niche social networking services focusing on
specific demographics sprang up, with the most successful example being LinkedIn,
which focused on business professionals. At the same time media content sharing
sites began slowly incorporated social networking service features and became social
networking services themselves. Examples include QQ (instant messaging), Flickr
(photo-sharing), YouTube (video-sharing), and Last.FM (music sharing).
As mentioned earlier, as of early 2010 social networking services are the dominant
service and purpose for many users on the Internet, with Internet traffic in US
surpassing the previous giant of the Internet.
Facebook is the most dominant social networking service till date, with 400 million
active users, 5 billion pieces of content shared each week, and more than 100 million
active users concurrently accessing Facebook through their mobile devices.
It is also the most widespread, with 70 percent of its users from outside of US, its
Mark Zuckerberg and some of his Harvard college roommates launched Facebook
in February 2004. Initially intended as an online directory for college students (the
initial membership was limited to Harvard College students) it was later expanded
to include other colleges, then high schools, and finally anyone around the world
who is 13 years old and above.
Facebook features are typically that of many social networks that were created
around that time. The more prominent ones are the Wall (a space on every user’s
profile five friends to post messages on), pokes (which allows users to virtually
poke each other, that is to notify a user that they have been poked), photo uploading,
sharing, and status updates, which allow users to inform their friends of their
whereabouts and what they were doing. Over time, Facebook included features to
form virtual groups, to blog, to start events, chat with instant messaging, and even
send virtual gifts to friends.
Facebook launched Facebook Platform in May 2007, providing a framework for
software developers to create applications that interact with Facebook. It soon
became wildly popular, and within a year 400,000 developers have registered
for the platform, and built 33,000 applications. As of writing date there are more
than 500,000 active applications in Facebook, developed by more than 1 million
developers and there are more than 250 applications with more than 1 million
monthly active users!
In this chapter we will be cloning Facebook and creating an application called
Colony, which has the basic but essential features of Facebook.
Online social networking services are complex applications with a large number
of features. However, these features can be roughly grouped into a few
User features are features that relate directly to and with the user. For example,
the ability to create and share their own profiles, and the ability to share status and
activities are user features. Community features are features that connect users with
each other. An example of this is the friends list feature, which shows the number of
friends a user has connected with in the social network.
Content sharing features are quite easy to understand. These are features that
allow a user to share his self-created content with other users, for example photo
sharing or blogging. Social bookmarking features are those features that allow users
to share content they have discovered with other users, such as sharing links and
tagging items with labels. Finally, developer features are features that allow external
developers to access the services and data in the social networks.
While the social networking services out in the market often try to differentiate
themselves from each other in order to gain an edge over their competition, in this
chapter we will be building a stereotypical online social networking service. We will
be choosing only a few of the more common features in each category, except for
developer features, which for practical reasons will not be implemented here.
Let’s look at these features we will implement in Colony, by category.
User features are features that relate directly to users:
- Users’ activities on the system are broadcast to friends as an activity feed.
- Users can post brief status updates to all users.
- Users can add or remove friends by inviting them to link up. Friendship in
both ways need to be approved by the recipient of the invitation.
Community features connect users with each other:
where any user can post on and can be viewed by all users.
Events pull together users, content, and provide basic event management
capabilities, such as RSVP.
people and pulls together users and content. Groups are permanent.
photos, pages, statuses, and activities. Comments are textual only.
including photos, pages, statuses, and activities.
Content sharing features allow users to share content, either self-generated or
discovered, with other users:
- Users can create albums and upload photos to them
- Users can create standalone pages belonging to them or attached pages
belonging to events and groups
You might notice that some of the features in the previous chapters are similar
to those here. This should not be surprising. Online social networking services
grew from existing communications and community services, often evolving and
incorporating features and capabilities from those services. The approach adopted in
this book is no different. We will be using some of the features we have built in the
previous chapter and adapt them accordingly for Colony.
For the observant reader you might notice that the previous
chapters have clones that end with clone. The original name of this
clone during writing was Faceclone, but apparently Facebook has
trademarked Face for many of its applications. In order to avoid
any potential trademark issues, ichose Colony instead.