Draft plan, nothing built yet

Market data: Databento futures ingest

How CME futures history gets from Databento into LRBO3, stays current every day, and reaches a backtest, all on Robodev. Options are sized at the end and need AWS when they start.

12 products
ES MES NQ MNQ RTY M2K GC MGC CL MCL BTC MBT
~15 GB
raw, 5 years, three schemas (measured)
~12 MB
new raw data per trading day
~1.4 GB
bar chunks in Postgres est.
$0
new infrastructure for futures

The short version: a scheduled Robodev job runs once a day. It reads how far each feed is loaded, pulls only the days after that from Databento, keeps the raw files in Robodev storage, and writes compact bar chunks into the Postgres the app already uses. A backtest reads only the chunks its date range needs. Nothing new is deployed: the job ships with the backend.

To clear out first

Three things are known constraints. The rest are unknowns that need an answer before the build starts, mostly from the Robodev team.

Known constraints

ConstraintWhat it means
DuckDB cannot run in RobodevRobodev installs only allowlisted JavaScript packages, and DuckDB ships a native binary. DuckDB is a laptop tool over the stored raw files, and there is no Parquet copy. If DuckDB must be part of the pipeline, the ingest has to run on AWS.
Options do not fit on RobodevAbout 725 GB a year and backtests that must run next to the data. Options need AWS when they start, whatever is chosen for futures.
Each environment holds its own dataPreview and production have separate databases and storage, so the backfill runs once per environment: twice the storage and twice the job time.

Unknowns to ask the Robodev team

UnknownWhat the plan needsIf the answer is no
Job time limit (timeoutMs)A minute or more per runFewer slices per run; the backfill takes more runs
Job memory~100 MB: one slice and one chunk at a timeDaily slices in the backfill too
Job overlap and queue limitsA job that queues itself thousands of times during the backfill, and a daily run that never overlaps one already runningA lock row in Postgres; a slower backfill driven by the cron alone
Storage quota and largest file~6 GB per environment, files up to ~20 MB, uploaded from memory in one pieceKeep no raw files and re-download from Databento when needed
Reading storage from outsideA way to list and download the raw files to a laptop for DuckDBAn admin route that hands out signed links (ctx.storage.getUrl)
Postgres quota~1.5 GB per environmentNo fallback on Robodev; the data has to live elsewhere
Postgres load during the backfillHours of chunk writes on the database the app is usingThrottle the job; run the backfill off-hours
Failure alertsSomeone is told when a daily run failsThe job sends an email itself (ctx.email); the app shows stale "data through"

Unknowns on the Databento side

UnknownWhy it matters
When a session becomes available on the historical API for our planSets the schedule hour and how fresh "data through" can be. One check with the key answers it.
Whether the $0 price holds for daily pulls and re-downloadsThe sizing run priced the 5-year pull at $0 on the current plan. The lookback re-reads three days every run.
Licence terms for storing the data and showing it to the client's tradersWe keep a full copy and display prices derived from it. Worth confirming against the plan's terms.

How it fits the existing system

vendorDatabentoGLBX.MDP3 historical API: definition, ohlcv-1m, statistics
robodev, newIngest jobjobs/market-data/ingest.ts, defineJob with a daily cron
robodev, new useStoragectx.storage: each raw slice as downloaded, gzipped, private
robodev, new tablesPostgrescontracts, bar chunks per contract and month, daily settlement and open interest, watermarks
existingBacktest runrecord loads the range, engine builds the continuous series and runs
laptop, reads raw filesDuckDB analyticsA script syncs the raw files from storage; DuckDB reads gzipped CSV directly. For research and data checks, not on the path of a run.
unchangedEverything elseThe web app, the assistant, the audit chain, run exports and the Starbase deploy keep working as they do. Uploaded CSV and synthetic datasets stay for tests and demos.

What is pulled

SchemaWhat it gives usRecords, 5 yRaw sizePer day
definitionEvery contract: symbol, expiry, tick size, multiplier, instrument class8.98 M4.67 GB~3.7 MB
ohlcv-1mOne-minute bars per contract70.5 M3.95 GB~3 MB
statisticsSettlement price, open interest, cleared volume per contract per day79.1 M6.33 GB~5 MB

One run of the job

The backfill and the daily update are the same job. On the first run the watermarks sit five years back and the job works forward a slice at a time. Once caught up, each daily run moves them forward by one day.

  1. Read the watermarksOne row per product and schema: the last instant loaded. Also ask Databento how far the dataset currently goes (metadata.get_dataset_range, free).
  2. Plan the slicesOne slice is one product, one schema, one UTC day (one week during the backfill). The range starts at the watermark minus a 3-trading-day lookback and ends at the dataset's end. Definitions go before bars and statistics for the same days.
  3. Download a slice and store itfetch on timeseries.get_range as CSV with integer prices and timestamps. The gzipped response goes to ctx.storage under a key named after the slice, so a retry overwrites the same file.
  4. Parse and filterPlain TypeScript in packages/market-data: read the rows, drop spreads using the contracts table, convert prices to ticks (ADR-0003).
  5. Write PostgresUpsert contracts and daily rows. For bars, load the chunk of each contract and month the slice touches, merge the new minutes in, and write it back with its bar count and SHA-256.
  6. Check, then move the watermarkCompare the slice's row count with Databento's (metadata.get_record_count). Only when it matches does the watermark advance.
  7. Continue or stopThe job works through slices until its time budget is nearly used. If slices remain, it queues itself again (ctx.jobs.enqueue) and exits. The run and its counts go into ingest_runs.

Why a lookback

Final settlement and open interest for a session arrive the next morning, and the vendor can correct recent data. Re-reading the last three trading days every run picks that up. Every write is an upsert on a deterministic key, so reprocessing is harmless.

If a run fails

The watermark only moves after Postgres has the slice, so the next run starts from the same place and overwrites the same files and rows. A failed run is a row in ingest_runs with its error; the app shows "data through" from the watermarks.

The backfill

About 9,400 weekly slices (12 products, 3 schemas, 260 weeks), a few MB each. At a few seconds a slice that is several hours of job time, spread over many self-queued runs. It is started once by hand and can be stopped and resumed at any slice.

Schedule: cron: "0 6 * * *", daily at 06:00 UTC. A run with nothing new exits in seconds. The exact hour depends on when Databento's historical API releases the previous session; step 1 reads the available range instead of assuming it.

What is stored where

Robodev storage: the raw files

market-data/raw/glbx-mdp3/{schema}/{parent}/{yyyy}/{mm}/{slice}.csv.gz      as downloaded, never edited, private

Roughly 4-6 GB gzipped for the five years. est. If Postgres is ever wrong, it is rebuilt from these files without calling Databento again. They are also what DuckDB reads for analytics, and what moves to S3 unchanged when options start.

Postgres: what a backtest reads

TableKeyHoldsSize
futures_contractsproduct + expiry month (ES:2025-12)Raw symbol, last trading day, tick size, multiplier, first and last bar~2,000 rows
futures_bar_chunkscontract + monthThat month's 1m bars in the existing compact encoding (ticks, epoch minutes), bar count, SHA-256~1.4 GB
futures_dailycontract + trading daySettlement, open interest, volume~0.5 M rows
market_data_watermarksdataset + schema + productLoaded through, updated at36 rows
ingest_runsrun idStarted, finished, status, slices, record counts, errora few rows/day

Contracts are keyed by product and expiry month, not by raw symbol or instrument id: ESZ5 means December 2015 and December 2025, and instrument ids can be reused.

How a backtest reads it

2-year run, 1-minute barsTimeBasis
Read ~35 MB of chunks from Postgres0.2-0.5 sEstimate; depends on the hosted database
Decode 765k bars0.07 sMeasured on a laptop
Engine, 10 indicators, ~5,000 trades0.9 sMeasured: 450 ms per year
Total1.5-3 sRuns stay inside Robodev, synchronous as today

What changes in the repo

WhereChange
packages/market-data (new)Framework-free rules: slice planning from watermarks, the Databento CSV rows, outright filter, contract keys, merging bars into a chunk. Unit-tested without Robodev or Databento.
apps/robodev-be/jobs/market-data/ingest.ts (new)The job: thin wiring of the package to fetch, ctx.storage, ctx.db and ctx.jobs. Reads DATABENTO_API_KEY from ctx.env.
apps/robodev-be/database.tsThe five tables above.
apps/robodev-be/api/market-data (new)Coverage per product for the app ("data through"), and an admin route that queues a run or the backfill by hand.
packages/recordThe market dataset kind and range reads in Datasets; Runs passes its range through.
scripts/market-data-sync.ts (new)Downloads the raw files to a local folder for DuckDB.
docs/adr/0009The decision this page describes, once agreed.

Options, later

Options on ES, NQ and RTY are a different size class and do not fit on Robodev. The plain parents (ES.OPT, NQ.OPT, RTY.OPT) miss the weeklies and dailies; covering them takes 58 option products.

Last 12 months, all 58 productsRecordsRaw size
bbo-1m (best bid and offer per minute)8.83 B706.6 GB
definition36 M18.7 GB
Total, growing about 2.8 GB per trading day~725 GB

Storage

AWS S3. Raw compressed is roughly 150 GB and a Parquet copy roughly 70-110 GB. est., to measure on one month

Parquet is partitioned by underlying and trading day, sorted by expiry, strike and minute. Not Postgres: 8.8 billion rows would cost more to index than to store.

Does DuckDB work with it

Yes, this is what it is good at. It is a library inside the worker, not a server. It reads partitioned Parquet from S3 and skips what a query's filters rule out, so one underlying, one day and a band of strikes is tens of MB. It needs to run in the bucket's region with a few GB of memory.

What it does to the jobs

  • Ingest: a container on AWS (Fargate, 4 vCPU / 16 GB, ~20 minutes a day) with the same slice and watermark rules from packages/market-data, Databento's batch download for the 725 GB backfill.
  • Backtests: an options run cannot load its data into the Robodev process. It becomes an asynchronous job on a worker next to the bucket: the app queues it, the worker runs DuckDB plus the engine and reports progress and the result back.
  • Speed: tens of seconds to a few minutes for a year, against 1.5-3 s for futures. Unmeasured; it depends on how many strikes and expiries a strategy touches.

Infra price on AWS

  • S3: about $5-6 a month for one year of data, and the same again for each year kept.
  • Daily ingest: about $2 a month. Backfill: about $5-10 once.
  • Backtest worker, started per run (4 vCPU / 16 GB at $0.23/h): $0.01-0.03 a run, with a 30-60 s cold start.
  • Backtest worker, always on: about $170 a month, no cold start.

About $10-30 a month pay-per-run, $180-200 with an always-on worker. est., us-east-1 list prices

What carries over from the futures build: the slice and watermark rules, the contract keys, the raw files, and the engine, which is framework-free. What is new then: the AWS account, the bucket, the two workers, and the decision whether the rest of the app follows them to AWS.

Build order

  1. The unknowns at the top answered; ADR-0009.
  2. The five tables and packages/market-data.
  3. The job, run under robodev dev for one product and one month.
  4. Range reads in record; a real ES backtest end to end on that month.
  5. The backfill on the preview environment, then production.
  6. The daily schedule and "data through" in the app.