Scaling Reliability with a Couple Million Lines of Haskell
The notion that a couple million lines of Haskell code would be a recipe for disaster is a conventional wisdom that Mercury, a fintech company, has proven wrong. Despite having a team of generalists with little to no prior Haskell experience, the company has successfully maintained a large codebase and scaled its operations to serve over 300,000 businesses. The key to their success lies in their approach to system reliability, which goes beyond just preventing failures and instead focuses on building adaptive capacity.
This approach involves designing systems that can absorb variation, degrade gracefully, and make the right thing easy and the wrong thing difficult. In a fast-growing company with a rapidly changing team, this means encoding institutional knowledge in a form that survives the departure of individual team members. For Mercury, this has meant leveraging Haskell’s type system to preserve operational lore and make it difficult for engineers to accidentally do the wrong thing.
The company’s philosophy is centered around helping engineers avoid being woken up at 4 AM to deal with the fallout of a broken feature. Rather than being the quality police, they aim to provide guidance and support to ensure that systems are designed with reliability in mind from the outset. This involves asking questions like “what is the blast radius if this fails?” and “what does the rollback look like?” to ensure that potential issues are addressed before they become incidents.
The Misunderstanding of Purity in Haskell
One of the most consequential misunderstandings about Haskell is that purity is something the language is, rather than something that interfaces enforce. In reality, Haskell is not a magical machine that performs side effects despite being pure. Behind every “pure” function lies a complex system of mutable allocation, buffer writes, and other behavior that would alarm engineers if they discovered it in a junior engineer’s side project.
What makes Haskell’s purity acceptable is that the side effects are encapsulated such that the boundary cannot be violated. This design principle applies everywhere in production, where the goal is often not to avoid mutation entirely, but to contain it, make it legible, and verify that it stays contained. The right question to ask is not “is this pure?” but “where is the impurity, and how much of the codebase is allowed to know about it?”
This boundary-oriented view of purity sets up a more general pattern that recurs throughout production engineering in Haskell: dangerous things are tolerable when they are fenced in, carefully exposed, and hard to misuse. This is true of mutation, retries, transactions, state machines, distributed workflows, and type-level machinery.
Encoding Operational Lore in Types
Haskell gives engineers tools to encode operational lore in types so that it cannot be forgotten. This is perhaps the single most valuable thing the language offers a production engineering organization. By restructuring types to make the correct operational procedure the path of least resistance, engineers can ensure that critical invariants are preserved even as the team changes.
Consider a simplified version of a real pattern: ensuring that certain side effects happen transactionally with a database write. The naïve approach is to tell people to use the right function, but this works until it doesn’t, and “until it doesn’t” tends to arrive on a Friday afternoon when the person who wrote the wiki page is on vacation. A better approach is to restructure the types so that the only way to commit work is through a path that includes event publication.
This approach makes the correct operational procedure the only door in the room, and the type system preserves institutional memory and turns it into a hard-edged interface. When a new engineer joins and asks “how do I write a transaction?”, the type system answers them, and when a senior engineer leaves, the answer remains.
Who Wins and Who Loses in the Haskell Ecosystem
The winners in the Haskell ecosystem are companies like Mercury that have successfully scaled their operations using the language. These companies have demonstrated that Haskell can be used in production to build reliable systems that can absorb variation and degrade gracefully.
The losers are companies that have tried to adopt Haskell but have not been able to overcome the initial learning curve. These companies may have found that the language’s complexity and steep learning curve have made it difficult to attract and retain talent.
However, the biggest losers are likely to be companies that have not yet adopted Haskell or other functional programming languages. These companies may find themselves at a competitive disadvantage as they struggle to build reliable systems that can scale to meet the demands of their customers.
The Skeptical Case: What Could Go Wrong
One potential criticism of Mercury’s approach is that it relies too heavily on Haskell’s type system to preserve operational lore. What if the type system is not sufficient to prevent errors? What if the complexity of the system makes it difficult to reason about the correctness of the code?
Another potential criticism is that Mercury’s approach may not be scalable to other companies. What if other companies do not have the same level of expertise in Haskell or do not have the same resources to devote to training and education?
Next Steps: What to Watch For
One next step to watch for is the adoption of Haskell by other companies in the fintech industry. Will other companies follow Mercury’s lead and adopt Haskell as a way to build reliable systems?
Another next step to watch for is the development of new tools and technologies that can help make Haskell more accessible to a wider range of developers. Will new IDEs, libraries, and frameworks emerge that can make it easier for developers to learn and use Haskell?
Pick one tactic from this post and apply it today. Which one will you start with?
By Daniel Cross, Digital Growth Strategist at TrendFlashy
Ready to launch your own asset?
Check out our guide on Building a Profitable Online Business.
