Market Data Pipeline Engineering for Digital Assets: Collection, Parsing, and Storage

    This article presents a reusable engineering approach to handling digital asset market data snapshots. It explains how to model snapshots as three layers (instrument, quote, and statistics), how to build a collection layer with timestamp checks, exponential backoff, and client-side rate limiting, and how to validate contradictory data before storage. It also covers hot/warm/cold storage tiering, pre-aggregation, two-level caching, differential push, observability, and security practices, showing how to turn fragile scripts into a maintainable data system.

    1. Introduction: Why Market Data Pipelines Need Engineering Design

    In digital asset trading and quantitative analysis, market data is the starting point of the decision chain. The raw material is a snapshot at a given moment: trading pair identifier, market type, latest traded price, quote currency, 24-hour change amount and change percentage, open price, high, low, market cap, market cap ranking, and data update timestamp. A single snapshot carries limited information, but when these snapshots arrive continuously at sub-second frequency, ensuring that collection does not drop data, parsing does not introduce errors, storage does not overflow, and display does not lag becomes a classic distributed data engineering problem.

    Many teams initially use scripts to fetch data on a schedule and write it to files. This works in the short term, but three pain points soon appear. First, field definitions are inconsistent, as different sources define the same metric differently. Second, outliers pollute the data, for example when the change percentage contradicts the change amount. Third, there is a lack of observability, so no one notices when data is delayed. Using this type of market snapshot as an abstract sample, this article provides a reusable engineering solution.

    2. Data Model Abstraction: Split Snapshots into Three Entity Types

    Do not flatten all fields into a single table. It is better to split them into three layers by semantics.

    The first layer is instrument information, which describes “what this is,” including the instrument code, name, market type, and quote currency. This data changes very slowly and is suitable for caching.

    The second layer is quote metrics, which describe “how it is doing now,” including the latest price, open price, high, low, change amount, and change percentage. This data changes at high frequency and is the main source of write pressure.

    The third layer is derived statistics, which describe “its position in the global context,” including market cap and market cap ranking. These are derived from circulating supply and price, and update less frequently than price.

    An illustrative structure definition is as follows:

    1. {
    2. "instrument": {
    3. "symbol": "GLM",
    4. "pair": "GLMUSDT",
    5. "market": "CRYPTO",
    6. "quote_currency": "USD"
    7. },
    8. "quote": {
    9. "last": 0.09139,
    10. "open": 0.08869,
    11. "high": 0.09269,
    12. "low": 0.08759,
    13. "change": 0.002697,
    14. "change_pct": 3.041
    15. },
    16. "statistics": {
    17. "market_cap": 90541500,
    18. "rank": 168
    19. },
    20. "meta": {
    21. "source_ts": "2026-11-24T14:22:40Z"
    22. }
    23. }

    The direct benefit of this layering is that writes only update the frequently changing parts, reads can assemble data on demand, and cache invalidation policies can be set per layer.

    3. Collection Layer: Polling, Incremental Fetching, and Rate Limiting

    The core tension in the collection layer is balancing freshness against quota cost. There are three common approaches:

    • High-frequency polling: For major trading pairs, the interval can be compressed to the second level.
    • Medium-frequency polling: Long-tail instruments can be relaxed to the minute level.
    • Event subscription: If the data source supports push, prefer push to reduce unnecessary requests.

    Regardless of the method, three mechanisms must be implemented. The first is timestamp validation, using the data’s own update time to determine whether it is new data and avoid duplicate processing. The second is backoff retry, using exponential backoff on failure rather than immediate retries, to prevent an avalanche. The third is a request token bucket, actively rate limiting on the client side to flatten peaks.

    1. import time, random
    2. def should_fetch(last_source_ts, now_ts, min_interval):
    3. if last_source_ts is None:
    4. return True
    5. return (now_ts - last_source_ts) >= min_interval
    6. def backoff_sleep(attempt, base=0.5, cap=30):
    7. delay = min(cap, base * (2 ** attempt))
    8. time.sleep(delay + random.uniform(0, 0.2))

    4. Cleaning and Validation: Block Contradictory Data Before Storage

    The most common error in market data is not missing values but self-contradiction. Using the sample, the high of 0.09269 and the low of 0.08759 form the day’s range. The latest price of 0.09139 falls within the range, and the open of 0.08869 is also within the range. The change amount of 0.002697 added to the open exactly yields the latest price, and the change percentage of 3.041% matches it. These four constraints can be written as general validation rules:

    1. Low ≤ open and latest ≤ high;
    2. Latest − open ≈ change amount (allowing floating-point error);
    3. Change amount ÷ open × 100 ≈ change percentage;
    4. Market cap and rank should be non-negative integers, with a smaller rank meaning a higher position;
    5. The update time must not be significantly ahead of local time (to prevent clock drift from producing dirty data).
    1. def validate(q, eps=1e-6):
    2. assert q["low"] <= q["open"] <= q["high"]
    3. assert q["low"] <= q["last"] <= q["high"]
    4. assert abs((q["last"] - q["open"]) - q["change"]) < eps
    5. assert abs(q["change"] / q["open"] * 100 - q["change_pct"]) < 1e-2
    6. return True

    For data that fails validation, do not silently discard it. Instead, write it to a separate quarantine area and trigger an alert, making it easier to trace whether the issue is in collection or at the source.

    5. Storage and Query: Hot/Cold Tiering and Pre-Aggregation

    Market data is a typical time series: write-heavy, read-light, and scanned by time range. A hot/warm/cold tiering approach is recommended. Keep hot data for the most recent days in high-performance storage, archive warm data monthly, and push cold data down to object storage compressed in a columnar format. Object storage is low cost with nearly unlimited capacity, making it suitable for long-term retention and offline recalculation.

    The key on the query side is pre-aggregation. Do not compute from raw points on every request. Instead, generate one-minute, five-minute, and one-hour candles and statistical metrics in advance. Illustrative logic is as follows:

    1. SELECT
    2. time_bucket('1 minute', ts) AS bucket,
    3. first(last, ts) AS open,
    4. max(high) AS high,
    5. min(low) AS low,
    6. last(last, ts) AS close
    7. FROM quote_raw
    8. GROUP BY bucket
    9. ORDER BY bucket;

    Combined with columnar compression and partition pruning, response times for historical range queries can usually be significantly reduced.

    6. Caching and Push: Reducing Read Amplification

    Market data is read-heavy and write-light, so caching yields high returns. A two-level cache can be used: a local in-memory cache serves the latest snapshots of hot instruments, while a distributed cache serves leaderboards and statistical results shared across instances. For update strategies, price data uses a short TTL plus active invalidation, while instrument information uses a long TTL.

    When pushing to terminals, differential push is recommended: send data only when a field changes beyond a threshold, avoiding meaningless network and rendering overhead. Thresholds can be adjusted dynamically based on instrument volatility, loosened for highly volatile instruments and tightened for less volatile ones.

    7. Observability and Alerting: Let the Pipeline Report Its Own Health

    A pipeline without monitoring is a black box. At least four types of metrics are needed: collection success rate, end-to-end latency, validation failure rate, and storage write error rate. Latency metrics should report both P50 and P99, as looking only at the average hides the long tail. Alerts should be tiered: a slight latency increase is only logged, while a sudden spike in validation failure rate triggers immediate notification to on-call staff.

    General logging, monitoring, and alerting services from cloud providers can be used for metric collection, dashboard visualization, and rule configuration. Container platforms can host elastic scaling for collection and compute tasks, and message queues can serve as a buffer between the collection and processing layers to smooth peaks and fill valleys.

    8. Security and Compliance

    Market data itself is not highly sensitive, but API credentials and access keys must be carefully managed, hosted through a key management service, and rotated regularly. Hardcoding them in code or images is prohibited. Externally provided query interfaces should enforce authentication and quota limits to prevent malicious scraping. All externally displayed data should be labeled with its source and update time to avoid misleading users about freshness.

    9. Conclusion

    By breaking a seemingly simple market snapshot into three layers—instrument, metrics, and statistics—and adding validation, tiered storage, pre-aggregation, differential push, and observability, a fragile script-based scraper can be upgraded into a sustainable engineering system. This methodology does not depend on any specific product. It can be deployed in a self-built data center or quickly built on general cloud product capabilities from Baidu AI Cloud. The core is always clear boundary definition and verifiable data contracts.