There are two ways to get a machine-learning prediction next to your data. The familiar one is to move the data to the model: extract it from the database, ship it to a Python service or a model-serving platform, run inference, and write the results back. The other is to move the model to the data: train and run it inside the database, where the rows already live. For decades the first approach was the only practical option, so it became the default and then the assumption. This post argues that for a large and growing class of workloads the assumption is now backwards — and walks through exactly where each approach wins, because there are real cases for both.
For the conceptual background, see What Is In-Database Machine Learning? and the AutoML guide.
The in-database engine here is SynapCores — vector, graph, SQL, and in-database AutoML in a single self-hosted binary, with native MCP and an OpenClaw long-term-memory plugin. The Community Edition is free. Download the free Community Edition →
The external pipeline, and what it really costs
The external pattern is well understood and well tooled. An orchestration layer extracts a training set, a training job produces a model, a registry versions it, a serving layer hosts it, and an inference path moves features out of the database and predictions back in. For large, custom deep-learning models trained on specialized hardware, this is the right architecture and nothing here disputes that.
The cost that gets undercounted is everything between the boxes. Each prediction in production means pulling features out of the database, serializing them, crossing the network to the serving layer, deserializing, inferring, and writing the result back. That is latency on every call and a second system to scale. Worse is the subtler failure: the features computed in the pipeline drift from the features in the live database, and the model that looked great in the training notebook quietly underperforms in production because it is being fed slightly different inputs. Training/serving skew is one of the most common and hardest-to-diagnose ML production bugs, and it is a direct consequence of the data and the model living in different places.
In-database ML: the model goes to the data
The in-database approach inverts the data flow. The model trains and runs where the rows are, so inference is a function call inside a query rather than a network round-trip to a service.
-- Train where the data lives
CREATE EXPERIMENT churn_exp AS
SELECT tenure_months, logins_last_30d, support_tickets, churned
FROM customers
WITH (task_type = 'classification', target_column = 'churned');
DEPLOY MODEL churn_model FROM EXPERIMENT churn_exp;
-- Predict inside an ordinary query — no extraction, no serving layer
SELECT customer_id, plan,
AUTOML.PREDICT('churn_model', tenure_months, logins_last_30d, support_tickets) AS churn_risk
FROM customers
WHERE plan = 'pro'
ORDER BY churn_risk DESC
LIMIT 50;
CREATE EXPERIMENT trains candidate models on the rows its SELECT returns and keeps the best one, DEPLOY MODEL gives it a name, and AUTOML.PREDICT scores rows with it inside a SELECT.
Three things change. There is no extraction and no serialization, so the latency of moving data disappears. There is no separate serving system to deploy and scale, so the operational surface shrinks. And because training and inference read the same live tables, training/serving skew largely goes away — the model is fed the exact features the database holds, by construction.