Engineering Social Commerce

Posted by on November 9, 2011

This holiday season we launched a redesigned version of a product we call “Gift Ideas for Your Friends”. The product works by connecting with your Facebook account, analyzing thousands or more of your friends’ likes and interests, and then making recommendations across millions of items in Etsy’s marketplace. Social commerce has been somewhat of a hot topic lately, and the gift recommender is a social commerce feature in that it provides a new and unique shopping experience to buy gifts for your friends and family. In this post we explore some of the engineering challenges we faced in building a social commerce feature like the gift recommender.

The gift recommender is social in that it brings your friends to Etsy. We all know shopping for friends and family is hard, particularly around the holidays when shopping lists grow quite large. Building a responsive experience here that allows navigation across your friends and their recommendations requires a tight coupling between client and server components as well as with Facebook’s API. On the commerce side of things, the product is powered by data mining algorithms that analyze contexts in both Facebook’s social setting and Etsy’s marketplace to make relevant recommendations. While developing these algorithms represents a challenge within itself, the coupling between these algorithms and the end design and user interaction is equally critical.

The end result is a product that requires integration among components across our entire stack, including: frontend html, css, and javascript, middle tier application logic and libraries, backend database interfaces and job queues, and hadoop driven recommendations. Let’s dive into some of the application’s core components, related system couplings, and some of the challenges we faced in building the product.

Tight integration with Facebook

The gift ideas product works by analyzing each of your friends. For each friend, we request various attributes, including name, education history, likes, interests, and activities. Facebook has a limit of 5,000 friends, but having friend counts above 1,000 is not uncommon. Furthermore, it is also not uncommon for people to have upwards of thousands of likes and interests. So, for a typical Facebook power user (read: your average graduate college student) requesting upwards of 100,000 attributes is not uncommon.

So how do we pull this amount data back from Facebook? First, you may have noticed that each friend is featured in a separated UI component which allows us to compute recommendations independently. When creating recommendations, we split up friends into groups of 50 and use our asynchronous job queueing system (powered by Gearman) to create recommendations in parallel. Each Facebook request is constructed using a series of fairly complex Facebook Query Language queries, a SQL like language supported by Facebook’s API. Some of these queries are extremely complex. For example, the query to fetch a user’s page likes looks something like this:

select page_id, name, type
from page
where page_id in (
  select page_id
  from page_fan
  where uid in (
    select uid2 from friend where uid1 = me() limit 50;
  )
)

Requesting data from Facebook is the slowest component of the recommendation creation process: some of our larger Facebook queries take multiple seconds to respond.

Performance: Caching, Caching, and Caching

The new design for the product displays many friends and their recommendations on the primary splash page. This is in contrast to the old design which only allowed for viewing of only one friend’s recommendations at a time. This presented several performance challenges.

Each Facebook attribute triggers a recommendation, and each recommendation shows items from the marketplace by issuing a search query. The new product displays four recommendations per friend in batches of 20 friends, so each batch can require as many as 80 search queries. Assuming an average response time of ~200ms per search, this could add up to load times in excess of 15 seconds. (!)

Luckily, the distribution of Facebook likes (and corresponding gift recommendations) is very sharp: the most popular 5,000 recommendations represent over 90% of all recommendations made by the product. Therefore, caching listing results at a per-recommendation level granularity provides us with tremendous speedups: 200ms search requests optimize to ~2ms memcache requests.

Client and Server-side Facebook API

We make heavy usage of the Facebook client API to authenticate users during initial Facebook connection phases: we did not want to recreate the javascript authentication flow supported by Facebook’s javascript SDK. However, we also needed server side API access for deeper queries required by the core recommender algorithm.

Complicating matters, we also recently released a feature that allows you to connect your Etsy account with your Facebook account. Managing tokens and authentication across the two systems while also allowing users to shop for gift ideas without an Etsy account presents several technical challenges.

Dealing with Backend Latency on the Frontend

Perhaps the biggest improvements made this year stem from a tighter coupling between the backend recommendation generation process and the frontend display. The initial creation process can take 3 or more seconds, and providing user feedback and context throughout is critical.

You may have noticed that your recommendations fill in “on the fly” as they’re created. As each of the asynchronous Gearman job workers completes its recommendation task, we stream results back to the client, which then renders them immediately via ajax. The end goal here is to enable the user to see recommendations appear as soon as possible, providing a more immediate shopping experience.

Data Mining

Of course, the core of the recommender system is the recommender algorithm and the supporting data. The core algorithm is responsible for understanding the meaning of a given Facebook attribute in an Etsy context. For example, the artist “Pink” is a popular musician on Facebook. However, a query for “pink” returns substantially different results on Etsy.

The core gift recommendation algorithm is overviewed in a post from earlier this year. We’ve also made several improvements since then. We’re smarter in analyzing gender when retrieving appropriate listing suggestions, and we’ve also taken another pass and removed bad listings based on data from the first year of the product.

Precision vs Recall, and the End Experience

“Gift Ideas for Your Friends” provides a different experience compared to other traditional recommender algorithms. For example, Netflix’s algorithms take a collaborative approach in which your entire profile is analyzed in aggregate, and recommendations are created by comparing your favorite movies compared to others.

In contrast, “Gift Ideas for Your Friends” makes point-based recommendations off of a single attribute of your friend’s Facebook profile. Jim likes burning man. Kurt likes video games. Chad likes Brooklyn.

In informational retrieval terms, the goal of the gift recommender is to optimize on precision: to make a handful of good recommendations based on a given set of attributes. There are lots of things that your mother likes on Etsy that aren’t represented in her Facebook profile, and the gift recommender will “miss” these recommendation opportunities. This is compared to Netflix style recommendations where the goal is to optimize for recall: given your entire movie history, provide recommendations that capture your taste as a whole.

In fact, for the general gift giving problem, optimizing for precision is a more natural objective: you generally buy your mother only a one or two gifts each year. Your mother might appreciate gifts like vintage glassware, amethyst jewelry, raku pottery, etc. A successful holiday gift really only requires buying her one of these items. Netflix style recommendations are aimed at capturing your various aspects of your taste and have stronger expectations for movie recommendations across all genres / styles that you may like.

The ultimate goal of the product is to provide a glimpse of Etsy through your friends and their existence on Facebook. We view the recommendations and sample results not as the final word in what to buy, but rather as a landing pad to dive into the marketplace. Diving into Chad’s recommendations for “Brooklyn” could then lead to a search for “brooklyn bridge” and purchasing an 8×10 photo.

At Etsy, we build our system in a continuously deployed environment which allows us to quickly iterate and experiment. We view everything we build as somewhat of an experiment, and the Facebook gifter is no exception. We look forward to the future of “Gift Ideas for Your Friends” and social commerce in general on Etsy.

Posted by on November 9, 2011
Category: data

8 Comments

Thanks for this info. I was hoping you guys would cover the use of Facebook’s API more in-depth. As you all are aware, there is a bit of uncertainty and questioning going around in the forums as to why was this feature placed on the front page? Also, why does it use the social plug-in in such a way that users who are currently logged into Facebook would automatically see these recommendations before they even have to log in to Etsy.com?

Yes, perhaps it would trigger a non-user’s interest into browsing the site based on those suggestions but from the social aspect, it may also come across as intrusive. I personally believe the feature has been nicely improved since last year, but the ‘super seamless integration’ factor may be far too advanced for most users just navigating through the page for the first time. I think there could be more added-value to this tool if Etsy introduced it to users in a more traditional way. Last year’s attempt would certainly not count as an initial introduction since the tool was vastly flakier.

Also, even when qualifying the existing login state of Facebook as an assumption that the use of plug-in is ‘expected or assumed’ by the user, this is not necessarily the case. Users may be logged into Facebook for different reasons such as using the ‘like’ button on a shop’s page. As well, a seller’s authorization to use Facebook in order to enable the ‘like’ button should not be utilized to display gift recommendations too. There are two very different features and should ultimately be selected/enable individually by users.

Moreover, attempting to disable the ‘instant personalization feature’ from Facebook would be expected to remove the gift recommendations feature (based on that option’s description and purpose) from Etsy but it doesn’t.

As a result, most users (especially sellers) will attempt to remove the Etsy ‘application’ access from their Facebook causing the ‘like’ button integration for Facebook Pages to be lost as well. I’m sure that all these scenarios have been discussed at one point or are currently being looked into. Unfortunately, the exposure this feature gets by being on the front page can significantly work as a disadvantage when improvements are needed.

Back to the feature itself, recommendation accuracy has definitely been improved. Aside from gender issues (example: 5 pairs of women earrings are the recommended gifts for my boyfriend this season – yay!), the other recommended gifts accurately match my friend’s ‘said’ likes. Sadly, I still can’t think of this being ‘front-page’ worthy. Most friends do not update their profile constantly and they usually list past interests which makes gifts recommendations more irrelevant.

tl;dr Props for the improved functionality, not front page worth it, may come across as spam/intrusive.

Good questions, and I’m glad you liked the improvement. The Etsy forums (http://www.etsy.com/forums) are almost certainly the right place to ask questions about how we make and prioritize product decisions.

@JASONDAVIS

Sorry if my post seemed to belong more to the Etsy Forums than here. I’m actually more interested on what FB plugins are being used and how (from a technical perspective). As well as how are users expected to interact, enable, disable them, etc.

[…] “Oh, Scoble, how can Facebook bring you better advertising?” Well, check out Etsy’s gift recommendation page. It’s driven by Facebook. It’s magical. It recommends gifts based on my friends and family’s Facebook behaviors. In the case of my producer, Rocky Barbanica, it’s VERY accurate. Too accurate to tell you here just what he’s into. Yes, he’s into the San Francisco 49ers, too, but he’s into a few other things I didn’t know about. Now I can get him that perfect gift. All because he shared his life with Facebook. UPDATE: Etsy wrote a blog post about how they made that. […]

[…] Etsy is widely known for their belief in automated software testing. You can read about their latest project in their developers’ blog at  http://codeascraft.etsy.com/2011/11/09/engineering-social-commerce/ […]

[…] and likes. Many are very accurate, and some I would actually consider buying. Etsy even wrote the behind the scenes post about how they made this service work. It would be interesting to see the results of this […]

[…] quotes, because there are only so many ways to describe it) recently launched an app on Facebook, “Gift Ideas for Your Friends” that uses FB data to pretty much do what it the title of the app says. I found out about while […]

[…] Engineering Social Commerce – Etsy and Facebook 1 Upvotes Discuss Flag Submitted 1 min ago Jonathon Colman E-Commerce codeascraft.etsy.com Comments […]