Over 100,000 lines of Elm code in production: Rakuten shares lessons learned
Japanese e-commerce company Rakuten recently shared their experience using Elm in production for over two years. Rakuten’s code base spans multiple applications on approximately 100,000 lines of Elm code. Rakuten really liked Elm’s approach to functional UI, its type system, and the lack of runtime exceptions. On the other hand, Elm is not a mainstream language, which translates to less reusable resources that can be discovered through Google search and Stack Overflow.
Rakuten’s engineering team described what prompted them to start using Elm for their application development as follows:
We decided to impose some discipline and start rewriting the functions in a 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 “Introduction to the Elm architecture and how to create our first application” […]. It was love at first sight.
The company gradually adopted Elm, starting with prototypes to test the technology first. While the results of the first trials were encouraging, Rakuten reported that Elm adoption had stalled somewhat due to a heavily server-side PHP codebase. A later battery change gave the company the opportunity to expand its use of Elm:
Several engineers were already pushing for a more functional way of writing code, and in a department heavily based on back-end APIs, there was a strong need for a decoupled way of writing user interfaces.
Fast forward to 2021, Rakuten now has around 100,000 lines of Elm code in multiple applications.
Rakuten has listed the benefits derived from Elm being a purely functional, static-type, domain-specific language specifically designed to be beginner-friendly.
Unlike TypeScript, type annotations are mostly unnecessary due to Elm’s strong type inference (annotations are considered good practice, however, to guard against infinite types). Elm’s strong type system allows Elm Package Manager to enforce semantic version control: API breaking changes are automatically detected and lead to major version updates. An Elm developer noted:
Compared to arbitrary version control systems where you have no idea if something is going to break or not, you have a bit more information about the nature of the upgrade. You still need to run tests and qualify for regressions, but overall I ran into maybe 3 minor regressions / fixes out of hundreds of upgrades, and none of them made it through. the production.
(Source: Elm in Rakuten)
Rakuten also mentioned the downsides that elm is not a common language. Almost a decade after its inception, and despite the aforementioned benefits of Rakuten, Elm has not gone mainstream, unlike TypeScript. Some developers believe this is because Elm was not designed for rapid adoption. The concrete consequences include not being able to rely on Google search and Stack Overflow as can be the case with traditional languages. This means having to write a custom Elm library if it does not already exist or is no longer maintained. Rakuten mentions having to write a library inspired by reaction-jsonschema-form to create HTML forms.
The full blog post has the full list of pros and cons of using Elm at Rakuten. Interested readers can view the full article online.