More than 100,000 lines of Elm code in production: Rakuten shares the knowledge gained
Japanese e-commerce company Rakuten recently shared its experience of using Elm in production for more than two years. Rakuten’s code base includes several applications with approximately 100,000 lines of Elm code. Rakuten valued Elm’s functional UI approach, its type system, and the lack of runtime exceptions. On the other hand, Elm is not a mainstream language, which means that fewer reusable resources can be found via Google Search and Stack Overflow.
The Rakuten engineering team described what led them to use Elm for their application development as follows:
We decided to impose some discipline and rewrite functions pure style2 to regain control of our application. […]
We thought: “If only we could find a tool to enforce these rules so that we don’t have to rely on our self-discipline …” and then we came across the post office “Introduction to the Elm architecture and how we create our first application” […]. It was love at first sight.
The company gradually took over Elm and initially started with prototypes to try out the technology. While the results of the initial tests were encouraging, Rakuten reported that the Elm rollout has stalled due to a heavily server-side PHP code base. A stack change later gave the company the opportunity to expand the use of Elm:
Several engineers were already pushing for a more functional way to write code, and in a department that relied heavily on back-end APIs, there was a strong need for a decoupled way of writing user interfaces.
In rapid succession until 2021, Rakuten now has around 100,000 lines of Elm code for several applications.
Rakuten listed the benefits of Elm being a purely functional, statically typed, domain-specific language designed specifically for beginners.
Unlike TypeScript, type annotations are mostly unnecessary due to Elm’s strong type inference (however, annotations are considered a best practice to protect against infinite types). Elm’s strong type system enables the Elm Package Manager to enforce semantic versioning: API-breaking changes are recognized automatically and lead to major version updates. One Elm developer noted:
Compared to any versioning system where you have no idea whether something is going to break or not, you have a little more insight into the nature of the upgrade. You still need to test and qualify for regressions, but overall I’ve seen maybe 3 minor / patch regressions on hundreds of upgrades and none of them made it into production.
(Source: Elm in Rakuten)
Rakuten also mentioned the downsides related to Elm not being a mainstream language. Almost a decade after its inception, Elm has not gone mainstream despite the aforementioned benefits of Rakuten – unlike TypeScript. Some developers think this is because Elm wasn’t designed with quick adoption in mind. Concrete consequences are that you cannot rely on Google Search and Stack Overflow as you can with mainstream languages. This means that if it doesn’t already exist or is no longer maintained, you’ll need to write a custom Elm library. Rakuten mentions having to write a library inspired by react-json-schema-form Create HTML forms.
The full blog post has the full list of pros and cons related to using Elm on Rakuten. Interested readers can read the full article online.