Skip to main content
IAM Strategy Report CIAM Buyer's Guide Contact Us
Janrain respects your privacy and will treat the personal data you choose to share with us in accordance with our privacy policy.
 

Functional Programming in the Social Web

By Larry Drebes | Posted on December 16, 2011

Blog Banner

At Janrain we like to use the right tool for the right job. The realm of social networking presents many challenges for implementers. There are components living in browsers, user interfaces, databases, and many web server applications. Different programming languages offer different strengths and weaknesses in each of these areas. We have found that functional programming offers significant advantages in the design and implementation of web servers. At Janrain we have been using the purely functional language Haskell, and the hybrid functional and object oriented language Scala as part of our toolbox for web servers.What makes functional programming a good choice for web servers in the social network? There are several factors:

haskell-scala

  1. Data structure intensive. The fundamental concept in social networking is the network. There are many ways to represent networks, including graphs, hypergraphs, and simplicial sets. Functional programming provides elegant ways to define and manipulate such libraries, and extensive libraries to assist the programmer in this area. Furthermore, both Haskell and Scala offer support for generic programming, wherein social network operations can often be defined once and reused for many relevant data structures.
  2. Concurrency: The services must be able to process many requests in parallel, and processing each request requires many activities that may be done in parallel, such as accessing a database, and contacting social network service providers. As a request is processed, the server may access or construct data structures; for example the server may construct a network of friends and friends of friends from several service providers. Another example is the processing of OpenID discovery for social login. OpenID discovery involves a sequence of discovery steps to different endpoints on the web. Many of these steps can be carried out in parallel. Haskell offers lightweight threads in support of concurrent programming, while Scala offers actors in support of concurrency. Concurrency and data structures are easy to combine in either Haskell or Scala. A sample that forks a thread for each element of a list in Haskell is shown below. Similar combinators can be defined for graphs and other data structures.
  3. High Availability: The services for the social network need to operate 24/7 in a highly available manner. Functional programming offers several features that support high availability. Scala has Finagle, which is an RPC system. Finagle can be used to implement availability concepts such as failover or m of n policies. Code should also be tolerant of errors. For example, in the code snippet below, each individual request could fail. The code returns a list of responses for those requests that succeed, and error codes for those that failed. The processing of the requests and responses will continue in spite of some failing requests. Thus the code snippet includes data structures, concurrency, and fault tolerance in just two lines of code.

At Janrain have found functional programming to be an important tool in support of social networking applications. We will continue to explore this valuable technology in support of social applications.

Popular Posts

About the author

Larry Drebes

CEO and CTO

Larry founded Janrain in 2005 to address the challenge of managing user identity on the Internet. In its early days, Janrain drove the development of the majority of the open source OpenID protocol libraries that continue to be used today by organizations such as Google and Yahoo!, and was a founding member of the OpenID Foundation, a nonprofit governance organization for the industry. Prior to Janrain, Larry was a co-founder of Silicon Valley startups Desktop.com, a web-based service, and Four11 Corporation. At Four11 Corporation, Larry led the development of its RocketMail product, one of the first Internet-based email systems. Four11 was acquired by Yahoo! in 1997, and its RocketMail product became Yahoo! Mail. Earlier in his career, Larry did software development for Raynet, McDonnell Douglas and A.G. Edwards.

View all posts by Larry Drebes