Crypto Market Data System Architecture: From Collection, Validation, to Distribution

    This article presents the complete technical architecture for building a cryptocurrency market data system, from collection to distribution. We break down the four core principles—separating ingestion from computation, validating before distributing, using tiered storage for hot and historical data, and relying on snapshots plus sequence numbers for recovery. We also discuss WebSocket connection management, hedging against data source failures, a unified data model for heterogeneous exchanges, precise calculation of 24-hour price changes, anomaly detection with circuit breakers, and storage strategies for caching versus historical data retention. All parameters, formulas, and thresholds are presented as configurable examples that require tuning based on each data source's API limits, load tests, and specific market volatility characteristics.

    Design Principles

    Four core principles guide the construction of a cryptocurrency market data system:

    1. Separate collection from computation. Fluctuations in upstream data sources should not directly impact downstream services.
    2. Validate before distributing. Invalid data must never enter the push pipeline.
    3. Store hot data and historical data separately. Each type of data should use its own engine and retention policy.
    4. Recover from disconnections using trading-pair snapshots plus sequence numbers. Do not rely on infinitely replaying historical messages.

    The scope of this system is: upstream connections to exchanges or blockchain data sources; middle-layer data cleaning and calculation; downstream push gateways serving mobile apps, web frontends, and institutional API clients. All values mentioned in this article are example parameters—they should be adjusted according to data source quotas, load test results, and business fluctuation patterns.


    Data Collection Layer: Multi-Source Ingestion and Long-Connection Management

    WebSocket Connections and Heartbeats

    For fields like latest price, high price, and low price that require second-level updates, HTTP short polling introduces excessive latency. WebSocket long connections are the appropriate transport mechanism.

    Each data source should maintain an independent connection pool. We recommend 2–4 connections per source, with subscriptions sharded by trading pair. The maximum number of subscriptions per connection depends on the data source’s documented limits and should be set explicitly in configuration.

    Heartbeat intervals follow each data source’s requirements; the example takes 15 seconds for ping. If neither a pong nor any market data push is received within 30 seconds, the connection is considered dead and a reconnect is triggered. Note that a market data push itself counts as a liveness signal, because some data sources skip the separate pong response during high message volume.

    Reconnection uses exponential backoff: the first wait is 1 second, doubling each time up to a maximum of 30 seconds, with random jitter added. If multiple collection instances reconnect simultaneously, they could collectively trigger rate limiting from the data source; jitter helps spread these requests.

    The subscription request rate must respect the data source quota. If a source produces no valid data for five consecutive minutes, the system should fail over to a backup data source and raise an alert, rather than waiting indefinitely.

    Standardizing Heterogeneous Data

    Different data sources return significantly different JSON structures—field names, precision, and timestamp formats all vary. Immediately after receiving a raw message, the system should map it to a unified internal model so that downstream modules depend only on this standard structure:

    1. {
    2. "symbol": "CUSDT",
    3. "market_type": "CRYPTO",
    4. "latest_price": 0.06172,
    5. "currency": "USD",
    6. "change_24h": 0.00070,
    7. "change_rate_24h": 0.01147,
    8. "open_price": 0.06102,
    9. "high_price": 0.06282,
    10. "low_price": 0.05992,
    11. "market_cap": 28290700,
    12. "market_cap_rank": 451,
    13. "update_time": "2026-11-24T13:14:34Z"
    14. }

    All timestamps use UTC. All price fields are stored as decimal strings or fixed-point numbers to avoid floating-point error. Mapping rules should be written as configuration tables—adding a new data source only requires adding a mapping, not modifying downstream code.


    Data Validation Layer: Calculation Semantics and Anomaly Filtering

    Defining the 24-Hour Price Change Calculation

    Price change percentages require a defined baseline; otherwise, the same number carries different meanings on different pages. This model uses a rolling 24-hour window: the baseline price is the last valid trade price exactly 24 hours before the current moment. In the model, this baseline is stored in the open_price field.

    The formulas are:

    • change_24h = latest_price − open_price
    • change_rate_24h = change_24h ÷ open_price

    Using the example data: the latest price 0.06172 minus the baseline 0.06102 gives 0.00070; dividing 0.00070 by 0.06102 yields approximately 1.15%.

    If a page needs to display “today’s open” (the open price at UTC midnight), it must be stored as a separate field and clearly labeled in the UI. These two definitions must never share the same field name.

    Edge cases need explicit handling:

    • For newly listed trading pairs without 24 hours of history, the change fields should be empty (null), not 0—otherwise users may assume the price has not moved.
    • If a long period passes without a trade within the window, keep the last valid price and mark the record as stale.
    • When messages arrive out of order, trust the data source timestamp; discard messages whose timestamp is earlier than the already-processed timestamp.

    Price Sanity Validation

    The validation rule is: low price ≤ latest price ≤ high price, and the latest price must be greater than 0.

    Example: the system receives a latest price of 0.06372 while the current high is 0.06282. Since 0.06372 > 0.06282, the data violates the rule. The system should log an alert, discard this record, keep the last valid snapshot in place, and wait for the next frame.

    Validation must run against the merged latest snapshot, not individual push fields. Some data sources send the latest price and the high price in separate messages with a time gap; validating single messages in isolation produces false positives.

    If three or more consecutive frames fail validation for the same trading pair, this typically indicates a mapping error or a source-side problem rather than random noise. At that point, stop pushing that pair and notify the engineer responsible for the mapping configuration.

    Price-Change Circuit Breaker

    If the latest price moves beyond a threshold relative to the previous valid price, the system should pause pushing and divert the data to an isolation queue. The threshold is configured per trading pair—the example takes 10%. Mainstream coins and small-cap tokens behave very differently in terms of volatility, so thresholds should be informed by historical volatility statistics.

    The isolation queue needs a clear processing policy. Each isolated record is retained for 60 seconds. Within that window, if two or more independent data sources produce prices that are mutually close (within the threshold), the system releases the data and re-pushes it to the distribution pipeline. Records that exceed the retention period without confirmation should be discarded and logged. A manual review interface handles cases the system cannot automatically resolve.

    The circuit breaker carries a misclassification risk. During violent market moves, genuine price jumps can also exceed the threshold—with the result that the displayed price lags behind the market. The breaker only blocks external pushing; internal calculation should continue uninterrupted. The system should also track the isolation ratio per trading pair. If the ratio for a given pair stays high for more than 10 consecutive minutes, escalate to an alert so a human can decide whether to lift the restriction, rather than letting automated filtering run indefinitely.


    Storage Architecture: Hot Data vs. Historical Data

    Hot Data Cache

    Fields with the highest access frequency—latest price, price change percentages, market cap rank, etc.—should be stored in an in-memory database. Given their read-heavy profile and tolerance for minute-level staleness in some fields, an in-memory key-value store serves these lookups efficiently.

    Memory capacity is directly tied to the number of trading pairs being tracked. Because in-memory storage is capacity-constrained, the retention policy must align with use cases: metadata derived from content, for example, can be fully cached and evicted based on recency rules, while fields that need permanent retention should be moved to the historical tier.

    A common pattern is a write-through cache: all writes also go to the persistent store for recovery and reporting purposes. To keep recovery efficient, the cache should periodically snapshot its state, so that on restart, the system loads from the snapshot and then applies incremental updates from a sequence-log.

    Historical Data Store

    Historical trade data accumulates indefinitely and is queried less frequently but in larger time ranges. A columnar database is the appropriate engine here—it compresses well for time-series data and efficiently serves range queries.

    The typical retention policy follows a tiered approach: keep raw tick data for a short window (e.g., a week) for debugging and replay; keep derived 1-minute, 5-minute, and 1-hour aggregates for extended periods (e.g., a quarter or longer); and keep daily aggregates indefinitely for long-term analytics.

    A consumer process should transform raw data into aggregates within a short delay window after ingestion, so that the hot cache and the aggregate tables stay consistent for downstream clients.


    Distribution Layer: Push Gateway

    The push gateway is the single egress point for all downstream consumers—mobile apps, web frontends, and institutional API callers. It maintains per-client subscription state and pushes only the pairs each client subscribes to.

    A CDC-style (change data capture) write pipeline is useful here: the gateway listens to changes from the hot cache, serializes each update into a compact binary or JSON message, and fans out to all active connections. Message batching and compression reduce bandwidth overhead.

    Delivery guarantees are pushed to the client layer in most cases. The gateway uses a heartbeat to detect dead connections and cleans them up. For clients that require ordered delivery, each message carries a monotonically increasing sequence number per trading pair. On reconnect, a client sends its last sequence number; the gateway responds with a snapshot followed by incremental messages.

    This design aligns with the fourth principle: recovery leverages snapshots plus sequence numbers, not unbounded replay of historical data.


    Operational Notes

    All parameters in this article are starting points, not recommendations:

    • Heartbeat interval: set per source, adjust to source behavior.
    • Reconnection backoff: 1s → 30s with jitter; verify under live failure conditions.
    • Validation thresholds: derived from per-pair volatility analysis.
    • Circuit breaker threshold: default 10%, but should be tuned per trading pair.
    • Isolation window: 60 seconds, adjustable.

    The system is deliberately modular: each layer (collection, validation, storage, distribution) is independently deployable. This separation keeps upstream data-source volatility from destabilizing the downstream pipeline, and lets the system adapt when new exchanges or blockchain data sources are integrated.