The Official Klout Blog

Scaling the Klout API with Scala, Akka, and Play

October 2nd, 2012 by David Ross


Back in March, Felipe Oliveira wrote about Klout’s new Sexy API. We had just released the Scala Play! Framework API infrastructure that we had been writing the previous few months. Not only did it represent a big step forward on the tech side, but it was also an important cultural change for Klout. Previously, disparate teams were responsible for their own serving infrastructure; now, having a central platform has empowered Klout to scale to a billion API requests per day and export powerful new functionality to partners.

But we still had a lot of work to do back then. By now, six months after launch, we’ve made some serious improvements to the API’s scalability and availability using Akka’s rich toolset for concurrent programming. Though Akka is mostly famous for its implementation of the Actor Model, I’m going to talk about two other Akka features, Futures and Agents.

Scalability with Akka Futures

For some background on the scalability problems we face, consider that serving a simple profile page like mine (see below), requires hundreds of lookups to several different datastores. Because of the scale of Klout’s data pipeline (expect a future blog post by Sreevatsan Raman to shed more light), we need to store users’ Scores, Moments, Topics and other data all in different datastores. As such, our app is very IO bound and optimizing our IO usage was one of our biggest priorities. We needed to do our IO concurrently.

dyross

Akka Futures (soon to be part of the Scala Standard Library) have proven to be the ideal tool for concurrent work. A Future represents an asynchronous computation and many Futures can be created in parallel. The Future API in Akka is very rich, but the key for us is its monadic nature. If you don’t know what a monad is, in Scala, it is something that has the map and flatMap methods. This allows Futures to be composed into new Futures with the syntactic sugar of a for expression. Compare this to Java Futures (java.util.concurrent.*), which have no means of composition.

Consider the following example, which has three methods that call different datastores and each return a Future:

[gist id=3815934 file=futuresSetup.scala]

Additionally, we have a resulting type we’d like to combine the results into:

[gist id=3815934 file=profile.scala]

Now, how should we do this? The non-monadic way, similar to how we would do it in Java, is to start each of the tasks, wait for them, and then build the result:

[gist id=3815934 file=futureBad.scala]

This is not ideal for a few reasons:

1. We are blocking on the execution of the concurrent tasks, which means the thread running this code must wait idly, wasting resources while the app is making network IO.
2. It is rather verbose and difficult to maintain.
3. This function violates the Single Responsibility Principle, because it is responsible for both the waiting of the Future and business logic for combining the results.

A better way to do this is with Future composition:

[gist id=3815934 file=futureGood.scala]

Notice how much more readable the code is. The for expression is sugar for calling the map and flatMap methods on the Futures, and the benefit is that we can refer to the results of the Futures in the yield block without waiting for them. This makes the method read more like a workflow and it is no longer concerned with waiting for the completion of the tasks.

One difference between the two methods is that the first returns a raw Profile and the second returns a Future[Profile]. This leads to an important realization, in the form of simple rules, we had while adding Futures to our code:

1. All methods that do IO should return a Future
2. Never block a thread waiting on a Future
3. Therefore, all methods that call other methods that return Futures must themselves return Futures.

In this way, we use Future almost like an IO monad (see this post for an introduction to functional IO). This allows us to push the Futures all the way up our call stack, finally wrapping them in Play’s AsyncResult in controller methods. Play handles these results in a non-blocking way, so we can be as efficient with IO as possible. (See the Play documentation for more detail).

Overall, the strategy of using Akka Future allows us to write more efficient and more readable code. I suggest becoming very familiar with the methods on Futures and the different ways to compose them, especially since they will be shipped with Scala 2.10 and later. The ability to write concurrent IO so easily is the key to our API’s performance and scalability.

High Availability with Apache Zookeeper and Akka Agents

Another one of our learnings in the last six months is that dynamic service discovery is key. For example, our MySQL cluster has one master and several slaves, and we spread read requests across the slaves as much as possible. Sometimes we need to dynamically remove slave nodes from the pool because of degraded performance or scheduled maintenance. Since we a large production cluster of API nodes, we need a to be able to make updates without re-deploying or downtime, giving our clients the best experience possible and guaranteeing that all nodes update within seconds.

Apache Zookeeper was an obvious solution for distributed configuration. To start, we created a simple wrapper for ZooKeeper on top of Twitter’s ZooKeeper client written in Scala. We use this wrapper to watch ZooKeeper nodes, issuing a callback inside our application whenever a modification happens:

[gist id=3815934 file=zk.scala]

But where should these callbacks go? One solution would be to create a service like this:

[gist id=3815934 file=stateBad.scala]

This service would keep track of nodes to read from, and we could use the zookeeper client to call updateState on the service. Any read request for MySQL would use the service to determine the pool of nodes to read from.

Again, there are a couple of problems with this:

1. The same class that deals with business logic is responsible for making updates, so the interface is not safe. Clients of this service would be able to make changes when we only want Zookeeper callbacks to make these changes.
2. This service would be prone to concurrency issues when multiple threads are making updates. These issues amplify exponentially if we want to add more features to our “MySQL State” than just “up” or “down”.

At first, we thought that Actors would be a good solution for this problem. However, we soon learned that because actors process all messages one at a time, the reads would get backed up. Also, the interface to the actors is Futures, which is more complex than necessary.

Akka thankfully provides an implementation of Agents, based off of the concept by the same name from Clojure. Agents wrap an instance of some type of state and support asynchronous single-threaded updaters and synchronous getters. For an agent of type T, the updater is a function from T => T, and the agent updates its state by changing its value to the result of the function applied to it’s previous value.

Here’s a similar implementation of the service above but using an Agent:

[gist id=3815934 file=stateGood.scala]

As you can see, the service is much simpler and the interface hides the updating access. Also, because the update functions are applied one at a time and simply add or remove nodes from the set, there is no concurrency issue. The biggest win, however, is that this allows us to think about our state as an immutable data structure, only responsible for dealing with business logic, and wrap the updating logic in the Agent. This gives us an elegant structure to our code.

We like this pattern so much that we use it wherever we have dynamic configuration depending on Zookeeper. It’s a great abstraction that allows for both more reliable and more readable code. And having this mechanism for dynamic service discovery gives the API fault tolerance and high availability it needs to meet its SLA.

Even if you are not using the Actor Model, Akka provides many tools to improve large concurrent enterprise systems. In some cases, other abstractions are simpler to use and require less boilerplate than Actors. At Klout, we believe in using the right tool for the job, so to help the Klout API meet SLA, we have used Future and Agents heavily. In doing so, we hope to push more and more of Klout’s data into the world. Let us know if you want to help.

Posted in engineering | 14 Comments »

Klout Begins Scoring Facebook Pages

September 28th, 2012 by Adithya Rao and Girish Lingappa


Our ongoing mission at Klout is to help everyone understand and be recognized for their influence. The more data we are able to measure, the more accurately we can represent your influence.

We’re excited to announce that starting today, Facebook Pages are integrated into the Klout Score! Facebook Pages are an extremely popular and important platform, where people, brands, and organizations actively engage with their communities.

The engagement volume is significant. For example, a Klout user with a score between 70-80 has an average of 13,000 users talking about their Page. This engagement explains why Facebook Pages have been one of the most highly-requested additions to the Klout Score.

In the chart below, you’ll find the new distribution of Klout Scores for users who have Pages, showing the contribution their Facebook Pages make to their Scores.

Your most influential Page content will begin appearing as moments on your Klout profile very soon. In the meantime, we invite you to be recognized for your Facebook Page influence. Connect your Facebook Page to Klout now by visiting your Connected Networks page in your Settings.

Q&A

How do I connect my Facebook Page to Klout?
Check out this step-by-step guide with screenshots in our Help Center.

How do I connect my brand’s Facebook Page to my brand’s Klout profile?
First, make sure that you are logged into your brand’s Klout account, not your own personal Klout account. Log out of Klout, sign in using your brand’s Twitter account, and then check in the upper-right hand corner to make sure your brand’s icon is there. That’s how you can make sure you are logged into the right account. Once that’s all set, you can follow our step-by-step guide to adding your brand’s Page.

How will adding a Facebook Page impact my Klout Score?
It depends. The mean Score increase for a Klout user with a Facebook Page is about seven points, all else held equal. Remember, other signals of influence from networks like Twitter and Google+ are still affecting your Klout Score and may offset score changes from your Page.

Please note that we only support having one type of Facebook account connected per Klout account: either a personal Facebook account or a Facebook Page. If you add a Facebook Page, it will replace your personal Facebook profile in terms of Klout scoring. You may see a Score drop if you replace an influential personal Facebook profile with a less influential Facebook Page.

What signals of influence from Facebook Pages are included in the Klout Score?
Some of the signals we’ll measure from Facebook Pages include the number of fans and how many people are talking about your Page. If you have connected your Facebook Page to Klout, you can check your Score Summary on your dashboard to see some statistics.

Will Facebook Page content be surfaced as moments on my Klout profile?
Not yet, but soon. Right now, your Page data is being incorporated into your Klout Score and into your Score Summary. Your most influential Page content will be surfaced on your Klout profile in the near future.

Posted in announcements | 25 Comments »

Bing Has Klout

September 27th, 2012 by Joe Fernandez


Klout’s vision is to help people understand and be recognized for their influence. I was surprised a few months ago after a meeting with the Microsoft Bing leadership to learn how much our visions overlapped.

Microsoft and Klout both believe that the growth of the social web and the increasing importance of your online identity are fundamentally transforming the Internet, making it even more important to understand people, not just pages. Like Microsoft, Klout is a friend to all social networks. We both want to help everyone discover relevant people regardless of the specific networks on which they’re active. And we believe we’ve only just begun to tap into the knowledge and insights “search through people” will enable, now and into the future.

To build towards that future, I am proud to announce that Microsoft has made a strategic investment in Klout and that we have signed a multi-year agreement where Bing will become one of Klout’s most significant partners.

Starting today, you will notice that Bing is surfacing Klout Scores and influential topics for experts that are listed in the “People Who Know” section of its social sidebar. The Klout Score and topics are a helpful signal for understanding why you should trust recommendations from these experts. By clicking through to those users’ Klout profiles, you can see their best moments and gain additional context and insights into their expertise. It’s the “social resume” at work!

Bing

As part of our partnership, Bing will provide additional data to Klout. Search data has long been one of the missing signals in our effort to fully recognize a person’s influence. Just as Wikipedia articles can reflect a person’s real world influence, search results for a person signal accomplishments achieved beyond social networks and serve to influence others. There will be two data points from Bing that will initially be highlighted as part of Klout moments. Experts who appear in Bing’s “People Who Know” section of the sidebar will be recognized on Klout. Influencers who have a Wikipedia account associated with their Klout profile will also be rewarded for the frequency that they are searched on Bing.

Over the next few months, we will include this data in the Klout Score and continue to add signals generated from Bing searches. The coverage of people who have Bing data associated to their Klout account will continue to increase as Klout helps surface more influencers in Bing search.

This is a small step for Bing and Klout towards a very big idea: search through people. You will see a continuous flow of innovation from our joint development team focused on the discovery and recognition of influencers on both Bing and Klout. If you haven’t registered your profile on Klout, now is a great time to start building your influence and making it easier for others to discover your passions and expertise on Bing.

Stay tuned for more updates on our collaboration with Bing and other Microsoft initiatives.

Posted in announcements | 93 Comments »

Klout Squad: What are the Qualities of a Great Blog?

September 21st, 2012 by Kameron Kitajima


The Klout Squad is an invite-only group of individuals who are passionate about social media, technology and Klout. The Klout Squad brings a unique perspective of views from Mom bloggers to social media gurus. Read their expertise on specific issues and questions. Click on their images to check out their Klout profiles.

Jessica’s favorite blog: Beyond the Brochure.
Chris’ favorite blogs: ZenHabits and ISO50.
Ben’s favorite blog: KissMetrics.

What qualities do you think make a great blog? Share with us some of your favorite blogs!

Posted in other | 2 Comments »

Klout for Good: Helping Put an End to the Illegal Wildlife Trade

September 12th, 2012 by Kameron Kitajima


Klout believes everyone has influence, and influence comes with responsibility. Klout for Good aims to help you leverage your influence to help make the world more a better place for everyone.

The illegal wildlife trade is estimated to be worth more than $10 billion per year and has drastically reduced many wildlife populations around the world. Every year, hundreds of millions of dollars are spent protecting animals in the wild, yet virtually nothing is spent on stopping the demand for wildlife parts and products.

WildAid, an international non-profit organization based in San Francisco, is the only organization focused on reducing the demand for endangered species products. With an unrivaled portfolio of Celebrity Ambassadors like Yao Ming, Jackie Chan, Harrison Ford and Leonardo DiCaprio, WildAid delivers high-impact, culturally sensitive multimedia campaigns reaching one billion people every week, globally.


forgood.klout.com

This month, we’ve partnered with WildAid to raise awareness and help put an end to the illegal wildlife trade. Visit the WildAid Klout for Good site, donate your influence, and sign the Global Pledge for Wildlife to call on the world’s leaders to ensure the conservation and protection of our planet’s wildlife.

Posted in Klout for good | 2 Comments »

Klout Moments for Everyone!

September 6th, 2012 by Joe Fernandez


It’s been about a month since we launched the most significant update to the Klout Score ever. Besides improving accuracy by adding sources like Wikipedia and greatly increasing the signals from every network we measure, this new score enables a level of transparency that has never been seen in the world of influence measurement. Since launching the updated score we have been rolling out an updated site that shows this transparency off through Klout Moments.

Today I am proud to announce that we have retired the old Klout site and everyone now has access to Klout Moments.

We are really proud of this update to Klout; it turned the heads of the press (see Time, Businessweek, PandoDaily) and turned critics into investors (see “Uncrunched: Why I Changed My Mind on Klout”). Since that day we have seen the highest registration and engagement metrics in our history.

This update to both the Klout Score and our site was a full company effort and we all hope you enjoy this release. One of the things we are particularly excited for you to experience is the pleasure of clicking around your friends’ Klout Moments. We’ve found it to be a fun reminder of how interesting, insightful, funny and influential our networks can be. We also built an incredibly robust privacy system that respects the viewing permissions of whatever network you created your moment on (Facebook posts set to friends only are only viewable by those Facebook friends on Klout, for example) and gives you full control over who has access to your moments.

Check out Klout.com now to see your most influential moments, and let us know what you think!

Posted in announcements | 17 Comments »

The Stories Behind the Score

August 24th, 2012 by Joe Fernandez


Last week Klout released a major update to our score model and a preview of our new moments feature that showcases your most influential social media activity. Internally the codename for this project was “Maxwell”, for the Scottish physicist James Clerk Maxwell, whose discoveries helped pave the way for modern physics.

The Maxwell project brought together a team of engineers, designers and product managers across Klout in a months-long effort to evolve the Klout Score and rethink how people can benefit from the insights Klout enables. We’ve gathered stories from a handful of the members of the Maxwell project for you here.

Big Data, Big Challenges
Andras Benke: I’m the technical leader of the Maxwell data and science team. We built up a big data pipeline based on a brand new architecture and completely replaced our scoring system.
Andras

Adithya Rao: I was responsible for building the scoring models for each network individually, and combining them together into the final Klout score. This also included extracting information from all the networks, as well as real world sources and using them meaningfully to count towards the score. Continuously tuning the models to be accurate, while meeting users’ expectations, was probably the most challenging problem I faced during the project.
Adithya

Nemanja Spasojevic: I worked on the backend data pipeline. We kept up with increasing demands for data quality as the project progressed, and with a high pace of iterations given the size of data. Processing and re-processing big data to make sure we kept up the development pace required, while still maintaining the legacy pipeline, required a lot of nerves from the team.
Nemanja

Girish Lingappa: During development and testing, we had to dig through millions of users’ scores and billions of messages to debug issues. Sometimes it felt like looking for a needle in a haystack.
Girish

David Ross: I am responsible for the data serving infrastructure for the Score and moments. including designing fast, scalable, and reliable API endpoints. Moments is the most challenging serving problem Klout has ever tackled. If you think about the amount of data that needs to get served to millions of users, moments is quite the scalability challenge. After many whiteboard sessions and iterations, we are making it happen.
Dave

Jerome Banks: I built out most of the data pipeline. Technically we had to deal with large datasets while still remaining agile. 
Jerome

Designing the Vision
Matt Sperling: The biggest challenge from a design standpoint was shifting the focus from the score to the story behind the score. Our solution was to show people the social interactions impacting their score on the dashboard, while giving them a showcase of their best moments on their public facing profile. Hence the design of interaction and moments. Alongside this we did a pretty substantial redesign of the site.
Matt

Mark Azevedo: I was responsible for building the original moments user interface prototypes. Now that we are no longer in the prototype phase, we will continue iterating on moments as a platform for revealing influence in your everyday social interactions. The Klout.com team who worked on the site redesign made it possible to support moments as a product.
Mark

Maxwell in the Real World
Adithya Rao: I am proud to be part of a team which was able to crunch such huge amounts of data and create a product that is hopefully going to redefine how people consume social data on the internet.

Nemanja Spasojevic: In the end, its the users that really matter. Being able to deliver on such an ambitious goal is the dream of any engineer.

Matt Sperling: I’m thrilled that we are giving Klout users a profile they can be proud of. It’s something they can show off no matter what their score.

Andras Benke: We are processing an amazing amount of data every day. Creating a stable system which is able to do this is pretty challenging even with today’s big data technologies.

What’s Next
The launch of the updated Klout score and moments is just one step on the road to helping everyone discover their influence. We’re excited about this release but we’ve already begun work on more great new features to come.

Posted in design, engineering | 29 Comments »

Klout for Good: Bring Clean Water to Rwanda

August 21st, 2012 by Kameron Kitajima


Klout believes everyone has influence, and influence comes with responsibility. Klout for Good aims to help leverage your influence to make the world a better place for everyone.

Clean water is a basic necessity that we easily take for granted. We can effortlessly fill our glasses from the faucet or buy bottles at a convenience store without a second thought. In other parts of the world, people are not as fortunate—800 million people don’t have access to clean drinking water. The hardest hit areas are in developing nations, like Rwanda, which is predominantly rural and one the most densely populated nations in Africa. Charity: water, a non-profit organization, helps bring clean and safe drinking water to people in developing nations. Charity: water is working directly with the people of Rwanda to raise $1.7 million, which would give 26,000 people in the Rulindo District clean and safe drinking water.


forgood.klout.com

Back in March 2012, we partnered with charity: water for its “Donate your Birthday” campaign, and more than 5,000 Klout users answered the call to donate their birthday toward clean water donations rather than receiving gifts. We’ve teamed up again with our friends at charity: water to help raise awareness about their “September” campaign. Visit the Klout for Good website, watch videos of personal stories from the people of Rwanda, and donate your influence by sharing the site with your friends and family.

Keep coming back to the site as we’ll be posting new video content every week until the end of their “September” campaign. During the final week of the campaign, we’ll bring you a live video of charity: water employees on the ground in Rwanda.

Posted in Klout for good | 3 Comments »

JAMBOX Heaven Starts Seven Days Early for Klout Users

August 21st, 2012 by Matthew Thomson


As you could tell from last week’s announcement about our updated Klout Score and redesigned website, we’ve been hard at work to evolve Klout in every way. We’ve always held the belief that everyone has influence, so we’re constantly on the move to find ways to bring value to all of our users. This means getting Klout influencers early access to exclusive products and experiences from top brands before they are available anywhere else.

This week, Jawbone, maker of JAMBOX—the #1 best-selling wireless speaker—has stepped up in a huge way, letting Klout users experience the newest JAMBOX a full week before anyone else.

You can be the first to build your own custom JAMBOX a week before it’s available to the public. Users can mix and match between 13 grill and nine cap options to create more than 100 design combinations to represent your favorite sports team (Hello 49ers!), alma mater, school, personal style—you get the picture. You can then share your designs with friends and grant them early access to create their own JAMBOX. Check out the landing page here to learn more.

“We’re excited to give Klout users the first peak at our new custom colors for JAMBOX. As a platform, we think Klout is a great way to engage influencers and encourage social sharing, and we can’t wait to see what color combinations are most popular amongst the Klout community,” said Travis Bogard, vice president of product management and strategy at Jawbone.

You might remember exclusive offers from Spotify, Microsoft and Audi that were only available to Klout influencers. Stay tuned – we’ll keep coming at you with more amazingness.

Posted in announcements | 7 Comments »

Discover Your Klout

August 14th, 2012 by Joe Fernandez


Social media is evolving every day. In just the past four years, we have seen Facebook grow from 100 million to over 900 million users. We’ve seen Twitter usage increase from 300,000 tweets per day to over 400 million tweets per day. LinkedIn has grown from 20 million to over 175 million users. The movement that grew out of college dorm rooms now has the power and scale to launch new markets and topple governments. And the rate of change is unprecedented in the history of technology and media. Since Klout was founded in 2008, we’ve seen the emergence and rapid growth of new networks, with many introducing powerful shifts in behavior, influence, and the way that ideas are shared.

Measuring all of this is a monumental challenge. Our team of engineers, scientists and hardcore social media users are obsessed with providing every person with the most accurate and transparent view of their influence and the power of their ideas. To accomplish this, we are constantly adapting and evolving our measurement to stay ahead of the social media growth curve.

Today, we’re introducing some of the most significant product updates in Klout’s history. With these updates, we’ve concentrated on helping everyone to gain a clearer, more accurate understanding of how they influence other people through the ideas they share.

Here’s what we’re announcing today:

  • Increased accuracy with an updated Klout Score that now includes significantly broader data sets and signals, including our first steps towards including real-world influence. We now include many more actions from Facebook, Twitter, Google+ and more, and for the first time incorporate Wikipedia as a signal. We’ve published more information about what goes into the Score here.
  • More transparency with a brand new feature called “moments” that showcases your most influential social media activity—the times when your ideas most impacted and touched the people in your world.
  • New, elegant site design that emphasizes your best content from across your connected networks.
  • More Data, More Often
    We have increased the number of social media signals we analyze from less than 100 to more than 400. We have also increased the number of data points we analyze on a daily basis from 1 billion to 12 billion. All of this additional data helps us deliver a more accurate Score for everyone on Klout.

    Real-World Influence
    Our long-term goal is to understand and analyze all the world’s influence, both online and offline. Today, we are entering the early stages of incorporating real-world influence into the Klout Score by integrating Wikipedia. We see a Wikipedia entry as a significant indicator of one’s ability to drive action in the real world. We’ve tested this method over the past several months and the updated Scores of recognized world leaders like Barack Obama and Warren Buffett more accurately reflect their real-world influence. Go here to see examples of how Scores are being calibrated by these new inputs.

    Distribution Shift
    The social Web is evolving, but one thing that’s not changing is the continued growth we’re tracking. Interaction and participation levels in the networks we measure are growing exponentially. We’ve adjusted the distribution of Klout Scores to better reflect the growth in engagement across the Web.

    Moments
    Moments is a significant addition to the Klout user experience. This feature displays the content and ideas that have been most influential across all of your networks, all in one place. Moments will also help you see interaction patterns emerge that can help you shape your influence and improve the quality of your ideas. We’ll make moments available to everyone over the next few weeks. You can also check out a preview here.

    Shiny New Site Design
    We’ve redesigned Klout.com to focus on the content that shapes your influence through each interaction. Our goal is to deliver a cleaner, more authentic representation of the insights and understanding you’ll now be able to get when you come to Klout. Like moments, we’ll initially make the new website design available to a small percentage of users and roll it out to everyone over the next few weeks.

    This update marks the next phase of Klout’s evolution into the dynamic, engaging platform of understanding and insight that I envisioned. Our ongoing vision is to help everyone discover and be recognized for their influence. Your ideas are more powerful than you can imagine, and with these updates to Klout, we are taking a step towards helping you understand that influence and better create ideas that shape the world around you.

    We know how important the Klout Score is to you. I look forward to hearing your feedback and hope you’ll find these updates to be as useful and awesome as we do.

    Posted in announcements | 184 Comments »