Legacy modernisation

Financial SQL · On-Demand Balances

A customer checking their lease account balance after a recent transaction would see a stale balance from the last payroll upload. Each upload triggered a full update across the lease-management systems, leaving them unavailable for ~34 minutes at a time.

AutoDash lease-details page with a balance breakdown, budget indicators and transaction history.
The lease-details interface brings balances, budgets and transaction history into one view. The screenshot illustrates the interface, not calculation timing.
01

The problem

The original stored procedure combined vehicle-lease calculations with old salary-packaging logic. It contained large commented-out sections and 36 unexplained constants (magic numbers). A payroll upload triggered an all-lease calculation and locked the system for roughly 34 minutes. There was no safe way to improve the performance until I could establish which financial rules were still active.

02

My role

I investigated the procedure, confirmed the meaning of its financial inputs with the Head of Accounts, refactored the calculation and connected on-demand balance requests through the Node.js API. I also retained the batch process needed for payroll and transaction imports.

03

How I changed it

Build a controlled investigation environment

I created a local LeaseCore SQL Server database using Docker with about 150 active leases and 50 ended leases with complete histories. I stepped through the procedure with database debugging tools, identified dependencies between calculations and checked undocumented constants against the business rules.

Refactor without silently changing balances

I removed code that could not be reached by the company’s vehicle-leasing workflows, then separated tax, lease-type, operating-cost and transaction-replay calculations into smaller units. After each change, I ran the original and modified procedure against the same leases and investigated differences before continuing.

Separate single-lease requests from necessary batching

A calculation for an individual lease took about 20 ms at the database and around 30 ms through the monitored Node.js API in testing. I used the API route for on-demand balances because it provided a clearer place for logging and failure handling. The required full batch still blocked the application, but its runtime fell to 12–13 minutes and it was scheduled for 1:00 am rather than during normal business hours.

React lease-detail requests mapped to stored-procedure calls, with unavailable SQL bodies marked as an evidence boundary.
The diagram maps the application calls visible in the reviewed source. The stored-procedure bodies were unavailable in that source snapshot, so it does not verify the SQL refactor or timings described here.
04

The result

Staff and customers could request an up-to-date individual balance without triggering a database-wide batch. During the investigation I also found approximately $528,000 in negative balances on closed leases that the existing deficit reporting had missed. The accounts team introduced a weekly report and later recovered just over half of that identified amount.

The full-batch and individual-lease figures measure different operations: the change removed the need to run the batch just to display one current balance.

Mobile AutoDash lease-details page showing the balance breakdown and budget indicators.
The mobile lease view presents the balance breakdown and budget indicators in a single column.