Why you shouldn’t use Stored Procedures in your code

Bending the Clean Architecture Principles

Anthony Trad
5 min readMar 11, 2023
meme

Introduction

This is one of few topics that still amazes me to this day… Stored procedures has been around from the dawn of time. Everyone had the pleasure of having those in his codebase but what amazes me is how this topic is constantly resurfacing in today’s world.

If it ain’t broke, don’t fix it !

I agree, but I find it odd that some of the most senior developers and craftsman still advocate for using Stored Procedures in your brand new system.

What are we talking about?

A Stored Procedure is just a function. The only difference would be that it is precompiled and stored in the database. Everyone knows SQL queries, procedures are just a precompiled set of queries that you can call whenever you need something.

For example, you‘re building an eshop website and you have a products table in your SQL Database. Let’s say you want you want to implement the search bar which searches for products with a certain name or description. There’s 2 simple ways of doing this:

  1. One could simply write a query that does just that:
SELECT * FROM products
WHERE name LIKE '%' +…

--

--

Anthony Trad

Senior Software Engineer focused on .NET and the Cloud. Reconsidering major principles and patterns, ideas are my own.