Future Twitter



Unsurprisingly, Future - who also dropped an album today - instantly became a trending topic on Twitter. And while some of the tweets celebrated 'The Wizrd,' others tore the rapper to shreds for. The Future of Twitter: Q&A with Jack Dorsey An in-depth conversation on 10 years of tweeting, the importance of live media, and “the puddle.” By Sarah Frier, Felix Gillette, and Brad Stone.

Microblogging platform Twitter has 32 million users, an increase from about 2 million a year ago, according to research mentioned in the Wall Street Journal. Some Internet measurement services show that figure increasing 50% to 100% month over month. While it is not clear that Twitter will become as large as social networks MySpace and Facebook or video-sharing site YouTube, the company could certainly have 50 million visitors by the end of the year.

Because Twitter can be used with ease on both PCs and mobile devices, and because it limits users to very short messages of 140 characters or fewer, it has become one of the largest platforms in the world for sharing real-time data. A number of large businesses and celebrities have hundreds of thousands of followers on Twitter. This includes personalities like Oprah and Ashton Kutcher. JetBlue (JBLU), Whole Foods (WFMI) and Dell (DELL), along with other multinational corporations, are among the most followed names on the service. (See the top 10 celebrity Twitter feeds.)

As Twitter grows, it will increasingly become a place where companies build brands, do research, send information to customers, conduct e-commerce and create communities for their users. Some industries, like local retail, could be transformed by Twitter — both at one-store operations that cater to customers within a few blocks of their locations and at the individual stores of giant retail operations like Wal-Mart (WMT). In either case, having the opportunity to tell customers about attractive sales and new products can be done at remarkably low cost while providing for greater geographic accuracy.

For Twitter to be a part of a company's efforts to communicate with customers, the customers must be willing to 'follow' the company on Twitter. That allows the individual consumer to choose which firms he is willing to get messages directly from. It may not be surprising that 'new age' brands like Whole Foods and JetBlue have large followings and older and much larger brands like Kroger (KR) and American Airlines (AMR) do not. Whole Foods and JetBlue have successfully marketed themselves as being 'customer-centric' — the kind of companies that would not misuse the access to a customer's private Twitter information. (Read Ashton Kutcher's take on why the Twitter founders made the TIME 100.)

While there may be commercial value for using Twitter to communicate with customers, the danger is that the Twitter community could turn against a marketer viewed as being too crass by being relentlessly self-promoting. Twitter users have set up their own rules of conduct when using the service, not unlike those with MySpace and Facebook. These rules were not put together by Twitter itself, which mandates only rules of use. Like many social-network sites, Twitter is self-governed by its members, and companies must take that into account as they join the service.

Twitter is still in the early stages of developing a plan for making money as a company, but plenty of large corporations like Starbucks (SBUX) are already using it as a marketing tool. Twitter will probably evolve into both a community of individuals and a community of companies that provide goods and services for those individuals.

24/7 Wall St. has come up with 10 ways in which Twitter will permanently change American business within the next two to three years, based on an examination of Twitter's model, the way that corporations and small businesses are currently using the service and some of the logical extensions of how companies will use Twitter in the future. Some of these firms are already using Twitter, but their efforts are in the earliest stages of development. 24/7 Wall St. evaluated other sensible and potentially highly profitable ways Twitter's real-time, multiplatform presence is likely to be exploited — in the best use of that word — to expand businesses both large and small.

Douglas A. McIntyre

NextHyper-Local Marketing

Finagle uses futures[1] to encapsulate and composeconcurrent operations such as network RPCs. Futures are directlyanalogous to threads — they provide independent and overlappingthreads of control — and can be thought of as featherweightthreads. They are cheap in construction, so the economies oftraditional threads do not apply. It is no problem to maintainmillions of outstanding concurrent operations when they arerepresented by futures.

Futures also decouple Finagle from the operating system and runtimethread schedulers. This is used in important ways; for example,Finagle uses thread biasing to reduce context switching costs.

The harmony of this analogy has one discordant caveat: don’tperform blocking operations in a Future. Futures aren’tpreemptive; they must yield control via flatMap. Blockingoperations disrupt this, halting the progress of other asynchronousoperations, and cause your application to experience unexpectedslowness, a decrease in throughput, and potentially deadlocks. Butof course it’s possible for blocking operations to be combined safelywith Futures as we’ll see.

Blocking or synchronous work¶

When you have work that is blocking, say I/O or a librarynot written in an asynchronous style, you should use acom.twitter.util.FuturePool. FuturePool manages a pool ofthreads that don’t do any other work, which means that blockingoperations won’t halt other asynchronous work.

In the code below, someIO is an operation that waits forI/O and returns a string (e.g., reading from a file). WrappingsomeIO():String in FuturePool.unboundedPool returns aFuture[String], which allows us to combine this blockingoperation with other Futures in a safe way.

Scala:

Java:

Futures as containers¶

Common examples of operations that are represented by futures are:

  • an RPC to a remote host
  • a long computation in another thread
  • reading from disk

Note that these operations are all fallible: remote hosts couldcrash, computations might throw an exception, disks could fail, etc.A Future[T], then, occupies exactly one of three states:

  • Empty (pending)
  • Succeeded (with a result of type T)
  • Failed (with a Throwable)

While it is possible to directly query this state, this is rarely useful.Instead, a callback may be registered to receive the results oncethey are made available:

Future Twitter Mother's Day

which will be invoked only on success. Callbacks may also be registeredto account for failures:

Sequential composition¶

Registering callbacks is useful but presents a cumbersome API. Thepower of Futures lie in how they compose. Most operations can bebroken up into smaller operations which in turn constitute thecomposite operation. Futures makes it easy to create such compositeoperations.

Consider the simple example of fetching a representative thumbnailfrom a website (ala Pinterest). This typically involves:

  1. Fetching the homepage
  2. Parsing that page to find the first image link
  3. Fetching the image link

This is an example of sequential composition: in order to do thenext step, we must have successfully completed the previous one. WithFutures, this is called flatMap[3]. The result of flatMap is a Futurerepresenting the result of this composite operation. Given some helpermethods — fetchUrl fetches the given URL, findImageUrls parses an HTMLpage to find image links — we can implement our Pinterest-style thumbnailextract like this:

f represents the composite operation. It is the result of firstretrieving the web page, and then the first image link. If either ofthe smaller operations fail (the first or second fetchUrl or iffindImageUrls doesn’t successfully find any images), the compositeoperation also fails.

Future Twitter Memes

The astute reader may have noticed something peculiar: this istypically the job of the semicolon! That is not far from the truth:semicolons sequence two statements, and with traditional I/Ooperations, have the same effect as flatMap does above (theexception mechanism takes the role of a failed future). Futuresare much more versatile, however, as we’ll see.

Concurrent composition¶

Future Twitter Page

It is also possible to compose Futures concurrently. We can extendour above example to demonstrate: let’s fetch all the images.Concurrent composition is provided by Future.collect:

Here we have combined both concurrent and sequential composition:first we fetch the web page, then we collect the results of fetchingall of the underlying images.

As with sequential composition, concurrent composition propagatesfailures: the future collected will fail if any of the underlyingfutures do [2].

It is also simple to write your own combinators that operate overFutures. This is quite useful, and gives rise to a great amount ofmodularity in distributed systems as common patterns can be cleanlyabstracted.

Recovering from failure¶

Composed futures fail whenever any of their constituent futuresfail. However it is often useful to recover from such failures. Therescue combinator on Future is the dual to flatMap: whereasflatMap operates over values, rescue operates over exceptions. Theyare otherwise identical. It is often desirable to handle only a subsetof possible exceptions. To accommodate for this rescue acceptsa PartialFunction, mapping a Throwable to a Future:

The following retries a request infinitely should it fail with aTimeoutException:

Other resources¶

  • Effective Scala contains a section discussing futures
  • As of Scala 2.10, the Scala standard library has its own futuresimplementation and API, described here. Note thatthis is largely similar to the API used in Finagle(com.twitter.util.Future), but there are still some namingdifferences.
  • Akka’s documentation also has a section dedicated to futures.
  • Finagle Block Party details why blocking is bad, and moreimportantly how to detect and fix it.

Future Twitter Stock

Footnotes

[1]Finagle uses its own Future implementation by a variety of reasons(fewer context switches, interruptibility, support for continuation-local variables,tail-call elimination), but mostly because it’s preceded SIP-14 by over a year.
[2]Use Future.collectToTry to concurrently collect a sequence offutures while accumulating errors instead of failing fast.

Future Twitter Wow

Future Twitter

Future Twitter Juice Wrld

[3]The name flatMap may seem strange and unrelated to our presentdiscussion, but its etymology is impeccable: it derives from a deeper relationshipbetween the sort of sequential composition we do with futures, to a similar sort ofcomposition we can perform over collections. See the this page for more details.