Skip to content

L&G Mortgage Engine

The estimation APIs behind an adviser’s in-home tablet, rebuilt legacy-to-reactive on an Akka stack, under full financial governance.

Legal & General’s mortgage advisers estimate what a customer can borrow on a tablet, in the customer’s own home. Behind that tablet tool sit the estimation APIs that run the calculation. The rebuild replaced the legacy implementation (large imperative methods in a pre-Spring Boot Java and Spring codebase) with a well-tested reactive one on Java, Scala, Akka and Play, in a governance framework where every change has to be auditable.

ScalaAkkaPlayJava

The problem: legacy logic, real-time setting

An adviser sitting in someone’s living room needs the estimate to be quick and available, on a tablet, over whatever connection the house has. The APIs behind it had grown over time as large imperative methods in an older, pre-Spring Boot Java and Spring codebase: dependable, but hard to change safely and awkward to reason about as a concurrent, real-time pipeline. The rebuild was about making it robust, testable and maintainable for that setting.

The rebuild

The engine was rebuilt ground-up within the existing platform, by a small, focused team across Scrum and Kanban. The legacy implementation gave way to a well-tested one on Java, Scala, Akka and the Play Framework.

The reactive core

Akka’s reactive, actor-based concurrency model fits what a real-time estimation pipeline demands. The async processing runs reliably under load, with cleaner separation of concerns across each computation stage: a stage of the calculation becomes its own actor with its own responsibility, rather than one more branch in a tangle of imperative code. The payoff was a measurable improvement in performance and reliability for the tablet tool advisers depend on, with direct commercial impact.

Before: one method for every stage

// One method carries every stage inline, branching in place and throwing on bad input.
def estimate(req: Request): Estimate = {
  val income  = validate(req)                 // throws on bad input
  val afford  = affordability(income)         // affordability rules, nested inline
  val product = lookupProductAndRate(afford)
  assemble(income, afford, product)           // one long method, hard to test in parts
}

After: a stage as an actor

// Each stage is an actor with one responsibility; stages compose by message,
// and a failure is a message rather than a thrown exception.
class Affordability(next: ActorRef) extends Actor {
  def receive = {
    case Validated(income) =>
      affordability(income) match {
        case Left(reason)  => sender() ! Rejected(reason)
        case Right(afford) => next ! Assessed(income, afford)
      }
  }
}
The mortgage estimation engine as a pipeline of stage-actorsA request flows left to right through four computation stages, each its own actor: validate, affordability, product and rate, and assemble, producing an estimate. Each stage has one responsibility and the stages compose by passing messages, running asynchronously.requestvalidateaffordabilityproduct + rateassembleestimateeach stage is an actor · async · one responsibility per stage
The estimation runs as a pipeline of stage-actors: each computation stage is its own actor with one responsibility, composed by message and running async under load.

Under governance

  • Every change, traceable. Working closely with product owners and compliance stakeholders, made each change traceable, auditable and aligned with regulatory requirements.
  • Through the approval process. Delivered engineering improvements through the structured release and approval process of a major financial-services organisation, without compromising a system advisers and customers depend on.