Result · Performance & Data · Financial systems

Reconciliation query: from 14 min to 7 s

A critical reconciliation query took 14 minutes and squeezed the processing window of an interbank card settlement platform. Rewritten and split into phases, with a composite index validated against the execution plan, it came down to 7 seconds.

  • 14 min per run, before
  • 7 s per run, after
  • 120× faster

Talk to Vinícius See what was done

Context

The problem

Reconciling means checking that what the system recorded matches what was settled. On an interbank card settlement platform, that check has a deadline.

The critical query behind it took 14 minutes per run, sometimes hit the timeout and squeezed the processing window.

Sector
Interbank card settlement
System
Critical platform at a regulated institution
Stack
Java · enterprise relational database · messaging
Authorship
Vinícius Andrade, as a contracted professional

The company name, the tables, the volumes and the original SQL were left out for confidentiality.

Step by step

What was done

Three changes to the query. For each one, what was done in this case and why that kind of change works.

  1. Rewritten SQL

    In this case
    The reconciliation query was rewritten: the same check, asked of the database in a different way.
    Why it works
    Two queries that return the same result can cost very different amounts of time. How a query is written decides where the database starts, how much it reads and when it discards what does not matter.
  2. Query split into phases

    In this case
    Instead of a single statement, the query was split to run in phases.
    Why it works
    A query that joins and filters everything at once can carry a huge set all the way to the end. In phases, each step hands a smaller set to the next and can be measured and tuned on its own.
  3. Composite index, validated against the execution plan

    In this case
    The query got a composite index, validated against the execution plan.
    Why it works
    A composite index stores more than one column, in an order, and only helps if that order follows the way the query filters and sorts. The execution plan shows whether the database actually uses the index and how much it stops reading. Without that check, a new index may only make every write to the table more expensive.

Result

From 14 minutes to 7 seconds

120 times faster: in the time the old query took to run once, the new one runs 120 times. The two lanes below run at their real duration.

Critical reconciliation query

14 min → 7 s

120× faster · interbank card settlement

In real timePaused

Follow-ups

Beyond the 7 seconds

What was proposed for the same query, and another result on the same system.

  • < 1 s proposed

    Proposed next step

    An idempotent pre-aggregation was proposed to bring the reconciliation under 1 second: totals are computed before the query runs, in a way that reprocessing never counts anything twice. It remains a proposal and is not part of the 7 s.

  • < 3 s

    On the same system

    Another query, with an N+1, was brought under 3 seconds with no new index.

Method

How the work is done

The routine is the same for any optimization.

  • Measure before touching

    Execution plan, traces and p95/p99 latency come before any change.

  • Change in small steps

    One change at a time, with the system running.

  • Test and alert with the code

    The fix ships with the test that proves it and the alert that warns if it regresses.

  • Recorded decision and runbook

    So the team can carry on without depending on whoever did the work.

Got a query like this in your system?

A query that hits the timeout or a batch that no longer fits the window: the conversation starts with the execution plan.

Talk to Vinícius See the other results