Case study: Fintech infrastructure

How VERKRIT restructured SQL Server procedures, stopped deadlocks, and added query caching for a regional lender processing ₹190+ Crore across 40+ branch offices.

Client Profile

Regional NBFC (India)

Volume Handled

₹190+ Cr, 60,000+ borrowers

Technology Stack

.NET Core, SQL Server, Redis

Engineering Leads

Anurag Singh, Raviraj Singh

Report Generation
65%

Latency dropped from 14.2s to 4.8s during morning branch hours.

Database Deadlocks
0

Eliminated roughly 35 daily lock escalation deadlocks across branches.

CPU Utilization
38%

Peak SQL Server CPU dropped from 92% to 38%, avoiding hardware upgrades.

01The challenge

Morning lock contention and 14-second query delays

The lender operates over 40 branch offices with 400 loan officers originating micro-loans, checking underwriting criteria, and recording repayments. Every morning at 10:00 AM, branch staff ran portfolio status reports while field officers submitted loan applications. The database server routinely pegged above 90% CPU.

Reporting queries took up to 14.2 seconds to complete. SQL Server also threw Deadlock victim exceptions on live loan disbursements because long-running cursor loops escalated row locks to entire tables.

02Root cause analysis

What the technical audit uncovered

Iterative cursor loops in stored procedures

A stored procedure calculating daily repayment schedules iterated over active accounts row by row with a CURSOR, holding shared read locks for the duration of the job.

Missing composite and covering indexes

Ledger tables with millions of rows were filtered by tenant ID and disbursement date, but indexes only covered individual columns. This forced clustered index scans on every report run.

Uncached master data

Branch configuration metadata, loan tier rules, and interest rate matrices were re-queried on every API request without in-memory caching.

Overly restrictive isolation levels

Reporting queries ran under serializable isolation by default, blocking concurrent write transactions during morning disbursements.

03Engineering solution

How VERKRIT stabilized the database

1. Replaced procedural cursors with set-based CTEs

We rewrote the 850-line stored procedure using Common Table Expressions (CTEs) and window functions like ROW_NUMBER() OVER PARTITION BY. The calculation now executes as a single set-based query in 1.8 seconds instead of iterating row by row.

2. Added covering composite indexes

We created covering nonclustered indexes tailored to the query execution plans:

CREATE NONCLUSTERED INDEX IX_Loans_Branch_Status_Date
ON dbo.LoanAccounts (TenantId, BranchCode, LoanStatus, DisbursedDate)
INCLUDE (PrincipalAmount, InterestRate, OutstandingBalance, BorrowerId)
WITH (ONLINE = ON, DATA_COMPRESSION = PAGE);
3. Added Redis caching and snapshot isolation

We set up a Redis cache layer for static loan rules and branch configurations, reducing database queries by 42%. We also enabled READ_COMMITTED_SNAPSHOT on SQL Server so reporting queries no longer block live disbursement transactions.

04Measured outcomes

Results over 12 months in production

  • Underwriting report generation time dropped by 65%, from 14.2s to 4.8s at the 95th percentile.
  • Lock escalation deadlocks stopped completely, saving an estimated 150 hours of branch staff waiting time per month.
  • Query optimizations avoided a proposed $35,000 database server hardware upgrade.
Experiencing slow database queries or concurrency bottlenecks?Discuss your codebase with our leads