Mercury Fintech Maintains 2 Million Lines of Haskell in Production Amidst Banking Stress
Ian Duncan, an engineer at Mercury, details how the company uses the Temporal framework and type-level invariants to manage a massive codebase that absorbed $2 billion in deposits during the Silicon Valley Bank collapse.
Mercury Fintech, a neobank serving more than 300,000 businesses, has successfully operated a production codebase comprising approximately 2 million lines of Haskell. Despite the language's reputation for complexity, the engineering team has maintained stability through significant stress events, including the collapse of Silicon Valley Bank in 2023. During that period, Mercury absorbed $2 billion in new deposits within five days, a surge that tested the infrastructure without causing system failure. The company is currently in the process of obtaining a national bank charter from the US Office of the Comptroller of the Currency (OCC).
The engineering philosophy at Mercury prioritises adaptive capacity over mere failure prevention. Reliability is defined by the system's ability to absorb variation and degrade gracefully, rather than simply the absence of bugs. This approach is essential for a rapidly growing organisation where personnel turnover is high. To prevent institutional knowledge from leaving when senior engineers depart, the team encodes operational invariants directly into the type system using rank-2 types and GADTs. This ensures that correct operational procedures remain the path of least resistance, even as the team composition changes.
To manage durable workflows, Mercury replaced fragile database-backed state machines and cron jobs with the Temporal framework. Workflows are treated as pure functions over event history, with side effects isolated in activities. This architecture ensures deterministic replay and robust handling of crashes, allowing the system to survive worker restarts and process failures without losing its place. The adoption of Temporal has substantially improved operational stability by removing the need for hand-rolled distributed state machines.
Addressing Haskell's lack of runtime monkey patching, the team implements observability via function records. Instead of exposing a module full of concrete functions, libraries expose a record whose fields are the functions. This allows cross-cutting concerns such as tracing, retries, and mocking to be injected at runtime without modifying library source code. This pattern solves the opacity problem in observability, ensuring that teams can instrument their systems effectively without forking code or relying on hope.
The company hires generalists and trains them in six to eight weeks, noting that while Haskell attracts idealists, active cultivation of pragmatism is required. The team avoids treating the type system as a religion, recognising that intense type-level machinery can become a liability if it leaks complexity across module boundaries. The goal is to build a system that a team of humans, including those new to the language, can operate and maintain.
Mercury processed $248 billion in transaction volume in 2025 on $650 million in annualised revenue, demonstrating the viability of their technical stack at scale. The engineering organisation largely hires generalists who have never written a line of Haskell before joining, proving that the language's steep learning curve can be overcome with structured training. The system continues to function as the organisation grows, proving that disciplined containment of compromise is more valuable than academic elegance in production environments.
