Real-Time Market Data Collection and Processing: A Practical Engineering Guide
A practical guide to building reliable market data pipelines, covering field semantics, data contracts, numerical precision, multi-source collection, freshness management, validation, tiered storage, service delivery, observability, cloud deployment, and compliance.
1. Starting with a Market Snapshot
In quantitative trading, portfolio dashboards, and risk alerting systems, market data is one of the most fundamental—and most underestimated—components. Below is a typical market snapshot with neutralized field names:
| Field | Value | Technical Meaning |
|---|---|---|
| Asset symbol | GLM | Unique identifier for the asset |
| Trading pair | GLMUSDT | Base asset + quote asset |
| Market type | CRYPTO | Digital asset market |
| Latest price | 0.09359 | Latest trade price, in USD |
| 24-hour change | 0.00009989 | Absolute price change |
| 24-hour change rate | 0.107% | Relative price change |
| Open / high / low | 0.09349 / 0.09539 / 0.09119 | Statistics for a rolling 24-hour window |
| Market capitalization | USD 93.7331 million | Price × circulating supply |
| Market cap rank | 164 | Result of a global comparison |
| Update time | 2026-12-01 19:50:38 | Time when the data was generated |
These ten fields may appear simple, but each one introduces clear engineering constraints. In practice, the challenge is not simply retrieving the data. It is maintaining consistent semantics, controlled precision, and measurable freshness.
2. Field Semantics and Data Contracts
2.1 Define the Contract Before Writing Code
One of the most common problems with market data is that identical field names can have different meanings. For example, “open price” may refer to the fixed opening price at 00:00 or the starting price of a rolling 24-hour window. Similarly, “market capitalization” may mean circulating market cap or fully diluted valuation.
The ingestion layer should therefore enforce a data contract, or schema, that specifies the unit, precision, time zone, statistical window, and null semantics for every field.
{"symbol": "GLM","pair": "GLMUSDT","market_type": "CRYPTO","price": {"value": "0.09359", "currency": "USD", "precision": 5},"change_24h": {"abs": "0.00009989", "pct": 0.00107, "window": "rolling_24h"},"ohlc_24h": {"open": "0.09349", "high": "0.09539", "low": "0.09119"},"market_cap": {"value": "93733100", "currency": "USD", "basis": "circulating"},"rank": 164,"ts": "2026-12-01T19:50:38Z"}
Representing numerical values as strings in the contract provides the first line of defense against precision loss.
2.2 Address Precision Issues Up Front
For low-priced assets such as one priced at 0.09359, a 24-hour absolute change may be as small as 0.00009989. If binary floating-point values are used for frequent aggregation and division, rounding errors can accumulate and eventually cause the percentage change and absolute change to become inconsistent.
A better approach is to:
- Use fixed-point or decimal types during ingestion and storage.
- Round values according to business precision only at presentation time.
- Validate that
abs_change ≈ price - openandpct ≈ abs_change / open. Treat deviations beyond a defined threshold as invalid data.
from decimal import Decimal, ROUND_HALF_UPdef normalize(raw):price = Decimal(raw["price"])open_ = Decimal(raw["open"])abs_chg = price - open_pct = (abs_chg / open_ * 100).quantize(Decimal("0.001"), ROUND_HALF_UP)return {"price": price,"abs_change": abs_chg.quantize(Decimal("0.00000001")),"pct": pct,"consistent": abs(abs_chg - Decimal(raw["abs_change"])) < Decimal("1e-8"),}
3. The Collection Layer: Multi-Source Ingestion and Freshness Management
A single data source will inevitably have blind spots. Mature implementations generally use multiple sources with a primary-backup design and cross-source validation:
- Prefer streaming, use polling as a fallback: Incremental streams over persistent connections provide low latency, while scheduled full-data retrieval fills gaps caused by disconnections.
- Use a consistent time standard: Store all timestamps in UTC and convert them to the user’s time zone at the presentation layer. Distinguish between the source generation time and the local receipt time. Their difference represents end-to-end latency.
- Make ingestion idempotent: Use
(symbol, ts, source)as the idempotency key to prevent duplicate counting when reconnects replay messages. - Evaluate freshness: Mark an asset as
staleif it has not been updated for more than N seconds. Exclude stale assets from ranking and alert calculations to prevent outdated prices from triggering false positives.
4. Data Cleaning and Standardization
The cleaning pipeline should be divided into four independently observable stages:
- Parsing: Map fields, normalize units such as millions and billions to a common base unit, and standardize currencies.
- Validation: Check value ranges, such as
price > 0; verify thatlow ≤ open/price ≤ high; and validate consistency between percentage and absolute changes. - Correction: Fill correctable fields according to predefined rules. For example, a missing opening price may be replaced with the first trade in the relevant window. Data that cannot be corrected should be moved to a quarantine area and counted.
- Standardized output: Write a unified schema to downstream systems and attach
quality_scoreandsourcelabels for troubleshooting and data lineage.
Quarantined data should not be discarded immediately. It is often the earliest signal that a source has changed its data format or semantics.
5. Tiered Storage and Computation
| Tier | Responsibility | Selection Approach |
|---|---|---|
| Hot | Latest prices, order books, and minute-level candlesticks | In-memory cache + time-series database |
| Warm | Daily aggregations, market capitalization, and rankings | Columnar storage that supports range scans |
| Cold | Complete historical archives and backtesting or recalculation | Object storage + partitioned directories |
Rankings and market capitalization are global aggregations. They should not be calculated independently on individual nodes. Instead, a dedicated aggregation job should generate periodic snapshots and write them with version numbers, ensuring that all queries read a consistent result for the same point in time.
6. Service Delivery and Observability
For external consumers, it is useful to provide three forms of access:
- Synchronous query APIs backed by the cache
- Incremental streaming over persistent connections
- Batch exports for cold or historical data
All three should use the same standardized data to prevent inconsistent definitions across interfaces.
Observability should cover at least four categories of metrics:
- Distribution of collection latency
- Data completeness
- Validation failure rate
- Number of stale assets
Alerts should be severity-based. Latency fluctuations are generally better handled with trend alerts, while sudden increases in validation failures and source disconnections should trigger immediate alerts.
7. Cloud Deployment and Security Compliance
In a cloud environment, the system can be assembled from general-purpose capabilities:
- Run stateless gateways on a container platform at the ingestion layer.
- Use message queues for buffering and decoupling.
- Store hot data in caches and time-series databases.
- Archive cold data in object storage.
- Send logs and metrics to logging and monitoring systems, respectively.
Baidu AI Cloud provides corresponding capabilities across these general categories, which can be scaled according to data volume.
From a compliance perspective, verify that the relevant market data is licensed for the intended use. Redistribution and republishing require confirmation of the applicable permissions. System output should also clearly state that it is provided for technical reference only and does not constitute investment advice.
8. Conclusion
The reliability of a market data platform does not depend solely on peak throughput. It depends on whether the contract is clear, precision is controlled, freshness is measurable, and anomalies can be isolated.
Once these four foundations are in place, low-latency optimization becomes much safer. Without them, an architecture may appear to work initially but fail as data volume and system complexity grow.
