Guide

Product price history database: schema design

Design a price history database that keeps every dated observation without overwriting earlier evidence.

Updated · datawebot team

A product price history database stores every dated price observation you collect, so you can see how prices moved instead of only what they are now. This guide is about its design: the tables, keys, storage choices, data-quality rules and queries that keep observations comparable for months or years. If you want a working script first, the Python price tracker tutorial builds a small version with an AI agent and one SQLite table; come back here when that table needs to grow.

A data source gives you snapshots. Most sources, datawebot included, do not keep a price history for you, so the history is whatever you store. Schedule the collection in your own application and keep each observation with its source, variant and retrieval time.

Why build a price history database?

Current prices tell you where the market is right now. Price history tells you where it has been, which is the context most pricing decisions need. With a well-designed history you can answer questions a single snapshot cannot: How did competitors respond to your last price change? How deep do discounts go during Black Friday in your category? Are prices trending up or down this quarter? How long do promotional prices last? For how to collect the prices in the first place, see the ecommerce price monitoring guide.

Trend detection

Spot long-term trends that are invisible in daily snapshots, such as a competitor raising prices gradually or eroding margins through repeated small discounts.

Seasonal analysis

Map seasonal patterns to plan your own promotions: when competitors usually start and end seasonal sales, and how deep the discounts go.

Price elasticity

Correlate your own price changes with sales volume to estimate price elasticity per SKU, and feed the result into your dynamic pricing rules.

Competitive response

Measure how quickly and how far competitors respond to your price changes, and use that to predict their behavior next time.

Database schema design

The schema determines which questions you can answer and how well the database scales. A time-series design works best: separate tables for products, sources and price observations, with one observation row per product variant, source and time.

Core schema

-- Products: your canonical product and variant reference
CREATE TABLE products (
 product_id UUID PRIMARY KEY,
 name TEXT NOT NULL,
 brand TEXT,
 gtin TEXT,
 variant TEXT, -- size, color or configuration; one row per variant
 category TEXT,
 created_at TIMESTAMP DEFAULT NOW()
);

-- Sources: where a price was read, and who sold it
CREATE TABLE sources (
 source_id UUID PRIMARY KEY,
 domain TEXT NOT NULL, -- e.g. 'walmart.com', 'amazon.de', a brand store
 country CHAR(2) NOT NULL,
 seller_name TEXT
);

-- Price observations: the time-series core
CREATE TABLE price_observations (
 observation_id BIGSERIAL PRIMARY KEY,
 product_id UUID REFERENCES products,
 source_id UUID REFERENCES sources,
 source_product_id TEXT, -- the shop's own ID (ASIN, item ID, variant ID), as a string
 price_minor BIGINT NOT NULL, -- 2999 = 29.99
 sale_price_minor BIGINT,
 shipping_minor BIGINT,
 currency CHAR(3) NOT NULL,
 condition TEXT, -- new, used, refurbished
 in_stock BOOLEAN,
 url TEXT,
 warnings TEXT, -- missing or partial fields reported with the observation
 retrieved_at TIMESTAMP NOT NULL
);
CREATE INDEX idx_product_time ON price_observations (product_id, retrieved_at);

Design tips: store prices as integers in the smallest currency unit (cents) rather than floating-point numbers, to avoid rounding errors, and always store the currency next to the amount. Keep the shop's own identifier as a string. Key an observation on source, variant and retrieval time, never on the product title.

Building the data pipeline

The pipeline moves results from your data source into the database. It handles ingestion, transformation, validation and loading on a schedule you run.

Ingestion

Retrieve results through your source's API, MCP tools or downloaded JSON or CSV, and load them with your own application. Buffer incoming data so no observations are lost when a run returns more than usual.

Transformation

Match each result to a canonical product and variant, clean malformed values, and compute derived fields such as price per unit or discount percentage. Keep the original amount and currency; convert currencies at query time.

Loading

Insert observations in batches. If you only want to keep price changes long term, apply change detection here, but keep full observations for a recent window (see below).

Storage options and trade-offs

The right storage depends on volume, query patterns and budget.

PostgreSQL with TimescaleDB

A good fit for teams already on PostgreSQL. TimescaleDB adds automatic time partitioning, compression and continuous aggregates, and handles millions of daily observations.

ClickHouse

Built for analytical queries on large datasets. High compression and fast aggregations suit read-heavy price history analysis at scale.

DynamoDB with S3

A serverless option for variable workloads: recent data and hot queries in DynamoDB, older observations archived to S3 as Parquet for cheap long-term storage.

BigQuery or Snowflake

Cloud warehouses that scale without infrastructure work. Pay-per-query pricing suits occasional analysis better than continuous dashboards.

SQLite

Enough for a single-machine tracker with thousands of rows, as in the Python price tracker tutorial. Move to one of the options above when you need concurrent writers or very large tables.

Data quality and deduplication

The reliability of your analysis depends on the quality of the history. Common problems: duplicate observations, misparsed currencies, promotional overlays read as base prices, and empty values from failed collections.

Add validation rules to the pipeline: reject zero or negative prices, flag prices that change by more than 50% between consecutive observations, and deduplicate consecutive identical rows if you keep change-only history. Put flagged rows in a quarantine table for review rather than deleting them, since flash sales and clearance prices can be real. Keep the warnings your source returns with each observation so partial records stay visible.

Querying and analysis patterns

Moving averages

7-day, 30-day and 90-day moving averages smooth daily fluctuations. Comparing the current price with its moving average shows whether a product is temporarily discounted or has shifted to a new level.

Year-over-year comparison

Comparing current prices with the same period last year shows seasonal and competitive shifts. It needs at least 12 months of history.

Price change frequency

How often each competitor changes prices, and by how much. Frequent small changes suggest algorithmic repricing; rare large ones suggest manual pricing.

Visualization and dashboards

Connect the database to a dashboard tool such as Grafana, Metabase or Tableau. The most useful chart is your price against matched competitor prices over time, annotated with launches, promotions and other events.

Scaling considerations

Observation volume grows with products × sources × checks per day. Tracking 10,000 products across 5 competitors with hourly checks gives 1.2 million observations a day. Plan for that from the start: partition tables by time, reduce the granularity of older data, and pre-compute common aggregations.

Designing scalable price history storage

A price history database has to balance write throughput for continuous ingestion with fast analytical queries. Time-series databases handle both by partitioning data by time and compressing older records. A common pattern is a hot tier for the last 30 to 90 days, stored for fast reads and writes, and a cold tier for compressed long-range history.

Design the schema around the queries you will run. Beyond price and time, capture the source marketplace, seller, condition, fulfillment method and any active promotion. That context lets you ask which sellers undercut on price and which compete on delivery, or how a promotion on one marketplace affects prices on another. Index for the most common patterns, usually one product over a date range and comparisons within a category, and use materialized views or summary tables for dashboard queries.

Price history database FAQs

Common questions about building and managing a product price history database.

How much storage does a price history database need?

One observation with metadata takes roughly 100 to 200 bytes. At 1 million observations a day that is about 6 GB a month uncompressed, or 1 to 2 GB with compression. Storing only changes can cut the volume further, because many prices stay the same for days.

Should I store every observation or only price changes?

Keep full observations for a rolling recent window, for example 7 days, to check collection quality. After that, change-only records are enough for long-term history.

Can my data source write directly into my database?

Usually not, and datawebot does not. Your application retrieves the results (over the API or the MCP tools) and inserts them, on a schedule you control.

How do I match products across different sources?

Use GTIN, UPC or EAN codes when both listings show them. Otherwise combine brand and model number, normalized titles and, if needed, image similarity. Keep a mapping table from each source's IDs to your canonical product IDs. The product matching guide covers the methods.

How much history do I need for useful analysis?

Competitor patterns start to show within about 30 days. Seasonal analysis needs at least a full year, and response modeling works best with 18 to 24 months. You cannot collect history retroactively, so start storing early.

How do I handle currency conversion?

Store the original price and currency code. Convert at query time with a separate exchange-rate table, so you can redo the analysis with other rates.

What is a time-series database and why does it suit price history?

A database optimized for data points indexed by time. Time-based partitioning, compression of sequential data and fast range aggregations make it faster than a general-purpose database for price trends.

What is Change Data Capture and how does it reduce storage?

Storing a new row only when the price changes. Because many prices are stable for days or weeks, it can reduce storage substantially. Keep a recent window of full observations for quality checks.

How should prices be stored to avoid rounding errors?

As integers in the smallest currency unit, such as 2999 for $29.99, with a separate currency column.

What data retention strategy works best?

Tiered retention: full resolution for 30 to 90 days, daily snapshots for the past year, and weekly or monthly summaries beyond that.

What is table partitioning and why does it matter here?

Splitting a large table into segments by a key, usually the observation time. Date-range queries scan only the relevant partitions, which keeps them fast as the table grows.

How do I detect collection errors in the history?

Flag zero, negative or sudden large changes (for example over 50%) and send them to a quarantine table for review. Alert on rising anomaly rates to catch systematic collection problems early.

What is a materialized view and how does it help?

A stored, pre-computed query result refreshed on a schedule, such as daily average price per product. Dashboards read it instead of scanning raw observations.

How should I index a price history database?

A composite index on product and observation time covers the most common query. Add one on source for cross-source comparisons, and avoid extra indexes that slow bulk inserts.

Append-only or upsert?

Append-only inserts every observation and keeps a complete audit trail. Upsert with change detection stores less. Append-only is simpler and keeps collection metadata; upsert is more storage-efficient long term.

How do I calculate a price volatility score?

Divide the standard deviation of prices over a window by the mean price for that window (the coefficient of variation). High scores mean frequent, large price changes; low scores mean stable pricing.

Read one product and every seller's offer as data.

Every account starts with 200 free credits, with no subscription: a search costs 5 credits and a product read 1. Failed requests are free.

← All articles