Stratify Continue with Google

Stratify / Guides / Engineering

Backtesting 372 Million Option Bars Your AI Never Sees: A Compute-to-Data MCP Server

How I built Stratify, an MCP server that backtests options on proprietary market data behind closed doors and returns only the outcome. The architecture in thirteen pictures.

· 3 min read

Specs go in, outcomes come out, and 372 million one-minute bars stay on the server.
Specs go in, outcomes come out, and 372 million one-minute bars stay on the server.

Many MCP servers fetch data and hand it to the model. Stratify does the opposite. The data stays on the server; the model sends a question in a formal language; the server runs it in private and sends back only the result.

The pattern

Real-world noise becomes a formal spec, runs behind closed doors, and comes back as an outcome.
Real-world noise becomes a formal spec, runs behind closed doors, and comes back as an outcome.

The AI is good at language and bad at arithmetic over a third of a billion rows. So the AI turns intent into a closed spec, and the server does the computing where the data lives. The spec is a grammar, not SQL or code, so every field can be checked and anything unknown refused.

The whole machine

One 8-core box. nginx in front, the API in a capped container, ClickHouse on a private network.
One 8-core box. nginx in front, the API in a capped container, ClickHouse on a private network.

One box, three layers, one way in. nginx is the only thing listening publicly. The API container listens on loopback only. ClickHouse has no host port at all, so the only route to the data runs through the API and back out as an outcome.

Resources

Four of eight cores for the API, a hard memory cap on ClickHouse, and a serving set small enough for RAM.
Four of eight cores for the API, a hard memory cap on ClickHouse, and a serving set small enough for RAM.

The API gets a hard cgroup cap of 4 cores and 4 GiB, so a burst of backtests slows down instead of starving the other services on the box. ClickHouse is capped at 45 % of RAM. The 11.3 GiB that backtests actually read is small enough to stay in page cache.

The data

From an 8-billion-row warehouse to the 53 rows one backtest hands to Python.
From an 8-billion-row warehouse to the 53 rows one backtest hands to Python.

ClickHouse because the workload is columnar scans over time-ordered bars. Precomputed layers because most questions only need near-the-money contracts close to expiry, and one row per contract-day answers every entry price without touching minutes.

Storage layout

Partitioned by month, sorted by contract: a one-year query skips seven years of history.
Partitioned by month, sorted by contract: a one-year query skips seven years of history.

That is why paid and free tiers share one database instead of two copies. Separating them would cost a second pipeline and buy 4 milliseconds.

Push the question to the data

The database finds the minute each exit fires; Python books 53 rows instead of walking 148,494.
The database finds the minute each exit fires; Python books 53 rows instead of walking 148,494.

The same principle as the whole system, one level down: send the question to the data, not the data to the question.

One request

A free-tier backtest end to end, with medians from 22 timed runs.
A free-tier backtest end to end, with medians from 22 timed runs.

ClickHouse answers in 23 ms. The other 175 ms is Python simulating fills, charges and statistics. That number decides how the system scales.

Reports

One stored result drives the report, the tearsheet and the replay; the AI gets the numbers and the link.
One stored result drives the report, the tearsheet and the replay; the AI gets the numbers and the link.

A result is stored once under an unguessable link. Every page is drawn in the browser from that result, so opening a report costs nothing and never re-runs anything.

Concurrency

Three gates between a crowd and the cores; overflow waits briefly, then gets a 429 with a retry time.
Three gates between a crowd and the cores; overflow waits briefly, then gets a 429 with a retry time.

Limits are per account, not per key, so minting keys buys nothing. The global slot counter lives in SQLite so all six worker processes share one limit. A short wait before refusing turns a brief overlap into latency instead of an error a model reports as a failure.

Capacity

Measured on 14 November 2026 on the 4-core allocation, 30 seconds per level, distinct specs so caches mostly miss.
Measured on 14 November 2026 on the 4-core allocation, 30 seconds per level, distinct specs so caches mostly miss.

The knee is 12 requests in flight: 21 backtests a second with the slowest 5 % under 0.8 s. Past it, throughput holds and only the wait grows. At one backtest per 20 seconds per person, that is about 400 people backtesting at the same moment.

Scaling

Throughput follows API cores; scaling out needs only a shared service database.
Throughput follows API cores; scaling out needs only a shared service database.

The bottleneck is Python on CPU, not the database and not the data size, so more cores means more workers. Scaling out is mostly a copy: the serving tables are rebuilt, never edited, so a replica is the same files on another machine.

Closed doors

Four independent rings: edge, identity, language, database.
Four independent rings: edge, identity, language, database.

Each ring holds even if the one outside it fails. A request has to pass all four, and raw rows have no route out through any of them.

Where this pattern fits

Any time the data is the moat: licensed market data, a company's internal records, regulated datasets, a proprietary model. Let the AI handle language and intent. Keep the data, the logic and the credentials behind a boundary that only lets outcomes out.

  1. Write down the constraint that can't move. Here: the data never leaves.
  2. Give the model a closed language, not a query interface.
  3. Push questions to the data instead of moving data to the question.
  4. Find what the work is bound by, measure it, and scale that.
  5. Make overload slow, not broken.
  6. Enforce every boundary twice, in layers that share no code.

The server is open source (MIT): github.com/Srinath-exe/stratify-mcp. Try it free at stratify.aeon-labs.site.

Backtest NIFTY and SENSEX options from ChatGPT or Claude. Free for the last year of data.

Start free with Google

More guides