Market Data Engineering for Decentralized Compute Assets: Modeling, Validation, Storage, and Observability
Market data pages often show only a price, a percentage change, and a few statistics, but behind them is a data pipeline with strict requirements for timeliness, consistency, traceability, and observability. Using market snapshots for decentralized compute assets as an example, this article presents a general approach to digital-asset market data engineering. It covers field semantics and data modeling, idempotent and out-of-order ingestion, validation, hot/cold storage and query design, API design, monitoring and alerting, and security and compliance practices. The architecture is product-neutral and can be implemented on general cloud infrastructure; Baidu AI Cloud is mentioned only as an example of generic container, message queue, object storage, logging, and monitoring capabilities.
Market data pages often present only a price, a change percentage, and a few statistics. From an engineering perspective, however, these values are backed by a data pipeline with high requirements for timeliness, consistency, traceability, and observability. This article uses market snapshots for decentralized compute assets as an example to abstract a general method for processing digital-asset market data. It discusses the complete practice from field modeling, ingestion validation, storage and query, and API design to monitoring, alerting, security, and compliance. The article does not depend on a specific third-party product, and the architecture can be implemented on general cloud infrastructure. For example, on Baidu AI Cloud, generic container platforms can host ingestion and computation services, generic message queues can decouple peak traffic, object storage can archive historical snapshots, and logging and monitoring/alerting capabilities can form a closed observability loop.
1. Field Semantics and Data Modeling: Align Definitions Before Discussing Real-Time Behavior
The core value of a market snapshot is the market state at a specific moment. Raw fields typically include asset code, trading pair, market type, latest price, quote currency, 24-hour change amount, 24-hour change percentage, open price, high price, low price, market cap, market cap rank, and update time. In engineering implementation, these fields should not simply be combined into one wide table. Their semantics and definitions should be clarified first.
First, asset identity and trading identity should be separated. Asset identity describes what asset it is, while trading pair describes in which market and in what quote unit it trades. Mixing the two prevents prices of the same asset in different quote markets from being aggregated correctly. A recommended model separates at least the asset dimension, market dimension, and snapshot fact table.
Second, price fields should have explicit precision and units. Latest price, open price, high price, and low price should use fixed-point decimals or high-precision decimal types consistently to avoid cumulative floating-point errors. Quote currency should be stored as an explicit field rather than implicitly expressed through field names.
Third, change definitions must be written into metadata. The 24-hour change amount and change percentage may be calculated based on different reference times. Engineering systems should record the reference time, calculation formula, and tolerance policy. If the change amount is 0 and the change percentage is 0, the system must determine whether this is a real no-change state, stale data, or an ingestion anomaly. A conclusion should not be drawn from the numeric values alone.
Fourth, time fields should be standardized to UTC while preserving original time zone information. Update time is not only a display field; it is also key to judging data freshness, handling out-of-order events, and building time-series indexes.
A general snapshot model can be represented as follows:
{"asset_id": "asset_x","market_id": "market_x","market_type": "spot","quote_ccy": "quote_ccy","last": 0.09359,"change_24h": 0,"change_pct_24h": 0.0,"open_24h": 0.09359,"high_24h": 0.09539,"low_24h": 0.09119,"market_cap": 93733100,"market_cap_rank": 164,"ts": "2026-12-01T19:53:38Z","source_seq": 1024}
Here, source_seq is used for idempotency and out-of-order detection, and ts is used for time-series partitioning. Fields such as market cap rank should be allowed to be empty because different data sources have different coverage. Missing data does not necessarily mean an anomaly.
2. Ingestion Pipeline: Idempotency, Deduplication, and Out-of-Order Handling
Market data ingestion generally has two modes: pull and push. Pull mode is simple to implement but requires frequency and timeout control. Push mode has lower latency but must handle disconnections, reconnections, and duplicate messages. In either mode, the principle of “land first, compute next, serve last” should be followed to avoid complex aggregation in ingestion threads.
An ingestion pipeline should include the following stages:
- The access layer handles authentication, rate limiting, timeouts, and retries. Retries must use exponential backoff with an upper limit.
- The raw layer retains original messages or normalized raw snapshots for auditing and replay.
- The message queue is used for peak shaving and decoupling. The message key can use the combination of asset and market to preserve ordering for the same instrument.
- The computation layer handles field validation, derived metrics, and anomaly isolation without directly modifying raw data.
- The service layer reads only validated data and uses caching to reduce hot-query pressure.
The key to idempotency is a business unique key, such as “asset + market + data time + sequence number.” Duplicate messages should be identified and discarded or overwritten rather than counted repeatedly. Out-of-order handling requires maintaining the latest time watermark for each instrument. Late messages can enter a backfill channel, but they must not overwrite newer snapshots.
3. Data Validation: Make Anomalies Visible Instead of Silently Swallowing Them
Common market data anomalies include negative prices, high price lower than low price, latest price outside the range, inconsistent change amount and change percentage, update time going backward, and abnormal jumps in market cap. Validation rules should be graded: hard errors are isolated directly, while soft errors are flagged and continue to be served. Example pseudocode is as follows:
function validate(snapshot, previous):if snapshot.last <= 0: return HARD_ERRORif snapshot.low > snapshot.high: return HARD_ERRORif snapshot.last < snapshot.low or snapshot.last > snapshot.high:return SOFT_ERROR("last_out_of_range")if snapshot.open_24h > 0:expected = (snapshot.last - snapshot.open_24h) / snapshot.open_24hif abs(expected - snapshot.change_pct_24h) > tolerance:return SOFT_ERROR("pct_mismatch")if previous exists and snapshot.ts <= previous.ts:return LATE_EVENTif snapshot.market_cap < 0 or snapshot.market_cap_rank <= 0:return SOFT_ERROR("cap_or_rank_invalid")return OK
Validation results should be written into quality metrics rather than only into logs. Hard errors enter a dead-letter queue, soft errors add quality flags to responses, and late events enter a backfill process. This keeps the main pipeline stable while providing evidence for later investigation.
4. Storage and Query: Hot/Cold Separation, Time-Series Partitioning, and Caching
Market snapshots have clear time-series characteristics. It is recommended to store latest snapshots and historical snapshots separately: latest snapshots serve low-latency queries and can use asset and market as the primary key; historical snapshots are partitioned by time for range queries and archiving. Historical data can be further separated into hot and cold tiers. Recent data retains high query capability, while older data is moved to low-cost object storage and read back on demand.
A general table structure can be designed as follows:
CREATE TABLE quote_snapshot (asset_id VARCHAR(64) NOT NULL,market_id VARCHAR(64) NOT NULL,market_type VARCHAR(32) NOT NULL,quote_ccy VARCHAR(32) NOT NULL,last_price DECIMAL(38,18) NOT NULL,change_24h DECIMAL(38,18),change_pct_24h DECIMAL(18,8),open_24h DECIMAL(38,18),high_24h DECIMAL(38,18),low_24h DECIMAL(38,18),market_cap DECIMAL(38,8),market_cap_rank INT,ts TIMESTAMP NOT NULL,quality_flag VARCHAR(32),source_seq BIGINT,PRIMARY KEY (asset_id, market_id, ts));
The query layer should avoid unbounded scans of large historical tables. List pages should read only the latest snapshot cache; detail pages should paginate by time range; statistical queries should preferentially use pre-aggregated results. Caches need reasonable expiration times and null-value caching policies to prevent cache stampedes. For hot data such as latest price, the cache can store a version number and update time, and responses can carry a stale flag so callers clearly understand data freshness.
5. API Design: Expose Definitions, Freshness, and Error Semantics to Callers
A market data API should return not only values but also definition metadata. A recommended response includes data time, ingestion time, sequence number, quality flag, and schema version. Example:
{"data": {"asset_id": "asset_x","market_id": "market_x","last": 0.09359,"change_pct_24h": 0.0,"high_24h": 0.09539,"low_24h": 0.09119,"ts": "2026-12-01T19:53:38Z","quality_flag": "ok","stale": false},"meta": {"schema_version": "1.0","pct_basis": "24h_open","server_time": "2026-12-01T19:53:40Z"}}
The API should clearly define rate-limiting policies, pagination limits, and error code semantics. Historical queries should use cursor pagination to avoid deep page numbers; real-time push should use heartbeats and reconnection mechanisms; anomalous data should return explainable quality flags rather than empty values. Callers can then decide whether to degrade display or trigger alerts.
6. Monitoring, Alerting, and Observability: Use Metrics to Drive Data Quality Governance
Observability for a market data system should cover at least ingestion latency, update interval, validation failure rate, late-message ratio, cache hit rate, API error rate, and stale-data ratio. Alerts should be graded: ingestion outages and long periods without updates are high-priority; soft errors for individual instruments can enter daily reports or trend-based alerts to avoid alert storms.
It is recommended to maintain a “last update time watermark” for each asset and market. When the difference between the current time and the watermark exceeds a business threshold, a staleness alert should be triggered. For price jumps, dynamic thresholds based on historical volatility can be used instead of fixed percentages. All alerts should be associated with asset ID, market ID, time window, and validation rule to support rapid diagnosis.
7. Security, Compliance, and Engineering Best Practices
Market data services should follow the principles of least privilege, key rotation, transport encryption, and audit trails. Ingestion credentials must not be written into code repositories; API access should support authentication and quotas; raw data and computation results should retain an audit chain to prevent tampering. External display should clearly state data definitions and risk disclaimers. Market data does not constitute investment advice.
At the deployment level, generic container platforms can run ingestion and computation services, message queues can buffer burst traffic, object storage can archive historical snapshots, and logging and monitoring/alerting capabilities can form a closed loop. Generic capabilities provided by Baidu AI Cloud can be used to host these components, but specific selection should be evaluated against throughput, latency, cost, and operations requirements.
Overall, the key to market data engineering for decentralized compute assets is not displaying a price. It is building a data pipeline where definitions are explainable, ingestion is idempotent, anomalies are isolated, history is traceable, and services can degrade gracefully. Only by moving field semantics, quality validation, and observability to the front can a market data service balance real-time performance and stability.
