Market Data Ingestion and Real-Time Monitoring: A Practical Technical Guide
A practical guide to building a verifiable, traceable, and alertable market-data pipeline: a source-agnostic snapshot model, hybrid collection with backoff, recomputed change metrics and layered validation, tiered storage, and four core observability signals.
1. Problem Definition: Why Market Data Is Hard
A typical market snapshot includes the instrument code, trading pair, market type, last price, quote currency, 24-hour change and percentage change, open, high, low, market cap, market-cap rank, and the data update time. The fields look simple, but the engineering difficulty concentrates in four places:
- Heterogeneous sources: Trading-pair names, market-type enums, decimal precision, and market-cap definitions differ across sources.
- High frequency and time series: Price series are inherently time-series data—writes are dense, and queries aggregate over time windows.
- Freshness sensitivity: Market data loses value quickly. Stale data is more dangerous than missing data.
- Outlier risk: Extreme moves, source jitter, and disordered timestamps all contaminate downstream calculations.
The goal is therefore not merely to “fetch the numbers,” but to build a data path that is verifiable, traceable, and alertable.
2. A Unified Market Snapshot Model
The first step is an internal standard model that does not depend on any source. External differences stay inside the adapter layer:
{"symbol": "XXXUSDT","asset_code": "XXX","market_type": "CRYPTO","quote_currency": "USD","last_price": 0.093590,"open_price": 0.093490,"high_price": 0.095390,"low_price": 0.091190,"change_24h": 0.000100,"change_pct_24h": 0.107,"market_cap": 937331000,"rank": 164,"source_ts": "2026-12-01T19:57:41Z","ingest_ts": "2026-12-01T19:57:43Z"}
Design points:
- Carry prices as fixed-point values or strings. Do not use binary floating point for core storage. Decimals such as 0.0935 accumulate rounding error across repeated calculations.
- Keep both the source timestamp and the ingest timestamp. The former aligns the series; the latter measures end-to-end latency.
- Label the definition of market cap and rank separately. Sources compute them differently, and mixing definitions causes rank jumps.
- Rank and market cap are low-frequency fields. Store them separately from high-frequency price fields to reduce write amplification.
3. Collection: Polling, Rate Limits, and Backoff
Collection uses push or polling. Push has lower latency but depends on connection stability. Polling is simpler and easier to scale horizontally. In practice, a hybrid of “push first, polling as fallback” is common.
import time, randomdef fetch_with_backoff(client, symbol, max_retry=5):delay = 0.5for attempt in range(max_retry):try:return client.snapshot(symbol) # adapter hides source differencesexcept RateLimited:time.sleep(delay + random.uniform(0, 0.2)) # jitter to avoid synchronized retriesdelay = min(delay * 2, 30)except TransientError:time.sleep(delay)raise DataUnavailable(symbol)
Key constraints:
- Exponential backoff plus random jitter, so many tasks do not retry at the same moment and create a second surge.
- Idempotent writes, using
(symbol, source_ts)as the business key so duplicate delivery does not create duplicate records. - Quota isolation, with rate limits by instrument group, so one high-frequency symbol cannot exhaust the overall quota.
- Circuit breaking: after consecutive failures hit a threshold, pause that source, switch to fallback polling, and raise an alert.
4. Derived Metrics and Data Validation
Do not trust a source’s change figures directly. They should be recomputable:
change_24h = last_price - open_pricechange_pct_24h = change_24h / open_price * 100
Validation rules should be layered:
- Structural checks: Drop records with missing required fields or illegal enum values, and count them.
- Range checks:
low ≤ last ≤ high, and the open price falls inside the day’s range. - Consistency checks: If the locally recomputed change diverges from the source value beyond a threshold, mark the record as suspicious.
- Time-series checks: Reject writes when
source_tsmoves backward or the span is abnormal. - Period-over-period checks: If the move versus the previous sample exceeds a configured multiple, send the record to a review queue instead of accepting it immediately.
Every rejected record must be persisted for later review. Do not drop it silently.
5. Storage and Query
- Hot data: Keep the price series in a time-series database, partitioned by time, retaining full precision for the most recent weeks.
- Warm data: Downsample to minute and hour aggregates for longer-term trend queries.
- Cold data: Archive in a columnar format to object storage for replay and offline analysis.
- Keep detail snapshots separate from aggregate tables. Query paths should hit aggregates first.
The typical query is “instrument + time window + aggregation granularity,” so the partition key should include both instrument and time to avoid full scans.
6. Observability and Alerting
Four metric classes cover most failures:
- Freshness:
current time − latest source_ts. Alert when it exceeds the threshold. - Coverage: ratio of instruments that should be collected to instruments actually stored.
- Latency: percentiles of
ingest_ts − source_ts. - Anomaly rate: share of records rejected by each validation rule.
Alert severity: freshness or coverage below the red line is urgent; rising latency or anomaly rate is a warning. Emit structured logs into a logging service so they can be aggregated and searched by symbol, source, and error code.
7. A Cloud Reference Layout
On Baidu AI Cloud, this path can be assembled from general product categories: a container platform for elastic scaling of collection and compute jobs; a message queue to buffer and smooth bursts between collection and consumption; object storage for cold archives; a time-series database service for hot data; and logging plus monitoring and alerting for observability. Components talk over standard protocols so implementations stay replaceable and the system is not tightly coupled to a single data source.
8. Practice Checklist
- Start with the internal model and absorb differences in the adapter layer.
- Use fixed-point prices and keep both timestamps.
- Back off with jitter, and keep writes idempotent.
- Derived metrics must be recomputable and attributable.
- Persist rejected data.
- Separate hot and cold tiers, and prefer aggregates.
- Track freshness, coverage, latency, and anomaly rate together.
Landed in that order, the market-data path can keep producing deterministic output when sources jitter, prices move extremely, or traffic spikes.
