← Back

2026-06-11

When Stored Procedures Are the Right Answer and When to Get Out of the Database

Somewhere around 2015, it became fashionable to declare stored procedures dead. Business logic belonged in the application layer. Databases were dumb persistence. ORMs would save us. Microservices would orchestrate everything.

Then I watched a Solvency II reporting pipeline take 14 hours because someone insisted on pulling 80 million policy records into a Python service to compute technical provisions row by row. The previous PL/SQL implementation ran in 22 minutes.

The question is not whether stored procedures are good or bad. The question is where the data lives, how much of it moves, and who signs the regulatory submission.

The Cost of Moving Data

Most architectural debates ignore physics. If you have 50 million transactions in Oracle and you need to aggregate them by counterparty, currency, and risk class, you have two options:

The second option is not just slower. It is slower by orders of magnitude, and it introduces failure modes that did not exist before: network timeouts mid-stream, partial reads, memory pressure on the app tier, retry semantics that may or may not be idempotent.

In BDDK and EIOPA reporting, where the same calculation may need to run nightly across years of historical data for back-testing, this difference is not academic. It is the difference between a pipeline that finishes before the regulatory deadline and one that does not.

When Stored Procedures Are the Right Answer

After 13 years of building reporting infrastructure for banks and insurers, the pattern is consistent. Push logic into the database when:

When to Get Out of the Database

The reverse is equally important. Pull logic out when:

The Hybrid That Actually Works

In practice, the reporting pipelines that survive contact with regulators look like this:

The database does what databases are good at. The application layer does what it is good at. Nobody pretends that one tool solves every problem.

The 2am Test

The real decision criterion is this: when the nightly run fails at 2am and someone has to fix it before the 8am regulatory submission, where do they look?

If the answer is "I check the database job log, find the failed procedure, read the error, and know exactly which 50 lines of PL/SQL to investigate," you have a maintainable system.

If the answer is "I trace the request through six microservices, correlate logs across four systems, figure out which container died, and then try to reproduce the data state," you have built something that looks clean on a whiteboard and is hostile to operate.

Regulatory reporting is not a place to optimize for architectural elegance at the expense of operability. The auditor does not care about your hexagonal architecture. The auditor cares whether the number is right and whether you can prove how it was calculated.

The Honest Framework

Stop asking whether stored procedures are modern. Start asking:

Answer those, and the right place for the logic usually becomes obvious. Ideology is what you reach for when you have not thought the problem through.