Facebook Open-sources Haxl: Implicit, Concurrent Data Access Using Haskell
Facebook has open-sourced Haxl, a library for efficient, concurrent data-access. The library leverages the traditional strengths of Haskell such as expressive type system, correctness and safety guarantees, as well as GHC's high performance run-time to solve the thorny issue of implicit, concurrent data access.
Haxl simplifies data access to remote data, such as databases or web services. It can automatically batch multiple requests to the same data source, request data from multiple data sources concurrently and also cache previous requests. Jon Purdy, one of the engineers who worked on Haxl, explains -
The basic idea here is that you can write naïve data fetching code that looks horrifically inefficient—queries in loops, no explicit deduplication—which gets turned magically into efficient concurrent fetching under the hood.
To use Haxl in your application, you need to create a thin layer that denotes your data source, and describes how to access it.
Haxl uses the Applicative type class to allow computations to be implicitly concurrent. You can read more about how it works in this presentation. The library can be found on hackage and you can access the source code on GitHub.
Haxl is a successor of FXL, which solves the same problem. Although FXL also has a pure execution model, it's implementation apparently has performance issues, especially with CPU and memory usage. Using Haskell, with the GHC, was the best alternative. You can learn more about the Story behind Haxl and the use-cases that Facebook currently uses it for.
Camille Fournier May 21, 2015