Stored Procedures Are Senior Microservices
Every decade, the industry reinvents something that already existed and calls it a revolution.
Microservices in the 2010s. Serverless in the late 2010s. Event-driven in the 2020s. Functions-as-a-Service for those who couldnât spell âserverless.â
I have been writing stored procedures since before your favorite JavaScript framework was a GitHub issue. And I am here to tell you: the database was right all along.
What Is a Microservice, Really?
Peel back the Kubernetes manifests and the conference slides, and a microservice is just:
- A small, isolated unit of computation
- With its own data ownership
- That communicates with other services
- Via some defined interface
Now look at a stored procedure:
- A small, isolated unit of computation â
- Inside the database (which owns all the data, as God intended) â
- That calls other stored procedures via
EXECorCALLâ - With a defined interface (parameter list) â
Congratulations. You have been writing microservices since 1992. Call your manager. You want a retroactive raise for the last 30 years of architectural innovation.
The True Service Mesh
-- UserService
CREATE PROCEDURE CreateUser(@name VARCHAR(100), @email VARCHAR(200))
AS BEGIN
INSERT INTO users (name, email, created_at)
VALUES (@name, @email, GETDATE())
EXEC SendWelcomeEmail @email -- calls EmailService
EXEC InitializeUserQuota @email -- calls QuotaService
EXEC LogAuditEvent 'user_created', @email -- calls AuditService
END
-- EmailService
CREATE PROCEDURE SendWelcomeEmail(@email VARCHAR(200))
AS BEGIN
INSERT INTO email_queue (to_addr, template, status)
VALUES (@email, 'welcome', 'pending')
END
-- AuditService
CREATE PROCEDURE LogAuditEvent(@event VARCHAR(50), @ctx VARCHAR(500))
AS BEGIN
INSERT INTO audit_log (event, context, created_at)
VALUES (@event, @ctx, GETDATE())
END
You now have:
- Service discovery: the database router
- Inter-service communication: procedure calls (sub-millisecond latency, no network hop)
- Transactions across services:
BEGIN TRANSACTION(something Kubernetes literally cannot do) - Shared infrastructure: connection pooling handled by the DB engine itself
The microservices community spent 10 years building Kubernetes to approximate what SQL Server has done since 1995. Think about that.
Triggers Are Your Event Bus
Youâve heard of Kafka? RabbitMQ? NATS? AWS EventBridge?
Cute. We have AFTER INSERT.
-- This is your event bus. No brokers. No consumer groups.
-- No "at-least-once delivery" incidents at 3 AM.
CREATE TRIGGER OnOrderCreated
AFTER INSERT ON orders
FOR EACH ROW
BEGIN
CALL ProcessPayment(NEW.order_id);
CALL SendConfirmationEmail(NEW.customer_id);
CALL UpdateInventory(NEW.product_id, NEW.quantity);
CALL NotifyFulfillmentWarehouse(NEW.order_id);
-- Fires automatically. In a transaction. Atomically.
-- Try doing that with your "distributed system."
END;
Event sourcing? Add an append-only audit table with triggers.
CQRS? Two procedures â one reads, one writes.
Saga pattern? A stored procedure with a TRY/CATCH block and a rollback table.
Every enterprise pattern has a stored procedure equivalent. The patterns were invented for people who donât have access to a real database.
As XKCD #327 immortalized, SQL is expressive enough to name your child
Robert'); DROP TABLE Students;--. Imagine what a trained DBA can do with your entire business logic.
Your Application Layer Is the Bottleneck
Letâs trace a request through a âmodern cloud-nativeâ stack:
Browser
â CDN
â Load Balancer
â API Gateway
â Auth Service (JWT validation)
â Business Logic Service
â Data Access Layer
â ORM (converts objects to SQL)
â Connection Pool
â Network
â Database (runs SQL)
Now with stored procedures:
Browser â Database
Count the failure points in each approach. Count the latency. Count the engineering salaries.
I have 47 years of experience. The answer is obvious.
Dogbert on Service Architecture
The PHB once summoned Dogbert as a consultant and asked: âHow do we make our distributed system more resilient?â
Dogbert replied, without looking up from his phone: âRemove everything between the user and the database. Bill me.â
The PHB didnât understand. He paid anyway. Dogbert bought a boat.
The consultant was right. He is always right. Thatâs why he charges $400/hour.
The Full-Stack DBA
With stored procedures as your service layer, the DBA becomes your everything:
| Traditional Role | In Database-First Architecture |
|---|---|
| Backend Developer | DBA |
| Microservices Engineer | DBA |
| DevOps Engineer | DBA |
| Platform Engineer | DBA |
| Solution Architect | DBA |
| Principal Engineer | Senior DBA |
| CTO | The DBAâs boss (barely) |
Fewer salaries. Fewer Slack channels. Fewer retrospectives. More stored procedures. More results.
Deployment Is Just ALTER PROCEDURE
Deploying microservices requires: Docker, container registry, Kubernetes, Helm charts, CI/CD pipelines, service meshes, canary deployments, rollback plans, deployment windows, change approval boards.
Deploying a stored procedure requires:
ALTER PROCEDURE UpdateUserProfile(@user_id INT, @name VARCHAR(100))
AS BEGIN
UPDATE users SET name = @name WHERE id = @user_id
-- done. deployed. no downtime.
-- no approval required.
-- no deployment window.
-- no postmortem if it breaks (just ALTER it again)
END;
This is what the industry calls Continuous Deployment. The âcontinuousâ part means you can do it any time, anywhere, including during a live demo to the CEO.
âBut What About Scalability?â
You will ask about scalability. Everyone does. It is the first refuge of engineers who want to seem smart without doing work.
Here is my answer: your startup has 200 users. You do not have a scalability problem. You have a premature optimization problem and possibly an ego problem.
When you actually reach the scale where stored procedures become a bottleneck, you will have enough revenue to hire someone who genuinely knows what theyâre doing. Until then: stored procedures, one database, one server, get to work.
Frequently Asked Questions
Q: Isnât this tightly coupling business logic to the database?
A: Your business logic IS the database. Youâre welcome.
Q: What if we need to switch databases?
A: You wonât. Youâve been using Postgres for 8 years and youâll use it for 8 more. Stop pretending.
Q: What about unit testing stored procedures?
A: If you need to unit test your database, you didnât trust your database enough to begin with. Thatâs a relationship problem, not a technical one.
Q: My team doesnât know SQL well enough.
A: Then teach them. SQL has been around since 1974. There is no excuse.
Q: What about NoSQL?
A: This conversation is over.
The author has been a DBA since 1987. He currently maintains 14,000 stored procedures across 6 databases. He is deeply content. His therapist retired early on his billing alone.