Designing a Market Data Processing and Visualization System for Crypto Assets

    A market snapshot is often the most visible output of a crypto asset data system, but displaying a price is only the end of a much longer data pipeline. This article walks through a general-purpose engineering approach covering field semantics and data contracts, a layered data model for snapshots, events and aggregates, ingestion and validation rules, indicator calculation and precision handling, cache layering and real-time push, observability and alerting, and security and deployment practices—so that a market data service remains maintainable, auditable, and scalable.

    A market snapshot is often the most intuitive output of a crypto asset data system: the latest price of a trading pair, the 24-hour price change, the percentage change, the open, high and low prices, market capitalization, market cap rank, and an update timestamp, all delivered to users through an API or a web page. From an engineering perspective, however, the snapshot is merely the final result of a long data pipeline. Behind it lie questions of field semantics, data contracts, ingestion and cleansing, consistency validation, precision handling, cache layering, real-time push, visualization, alerting, and observability. If a team focuses only on “displaying the price,” the system will quickly expose flaws when data is delayed, fields are missing, baseline conventions are inconsistent, or push updates become jittery. This article follows a general technical approach and discusses how to turn a market snapshot into a maintainable, auditable, and scalable data service.

    1. Define Field Semantics and the Data Contract First

    The first principle of market data is “semantics before everything else.” The latest price represents the most recent valid trade or aggregated quote at a given moment. The 24-hour price change and percentage change must have an explicit baseline: is it the closing price 24 hours ago, or the opening price of the current day? Different data sources may use different conventions, and if the API documentation does not spell this out, front-end displays and risk-control rules will diverge. The open, high, and low prices need a clearly defined statistical window—calendar day, rolling 24 hours, or a specific trading session. Market cap and market cap rank are derived indicators that depend on circulating supply, total supply, and price; their update frequency is typically lower than that of trade prices, so their freshness must be distinguished from price fields. Timestamps should use a unified timezone in ISO-8601 format, and the pipeline should preserve the source timestamp, the ingestion timestamp, and the storage timestamp so that latency can be diagnosed.

    It is advisable to define a stable data contract for the snapshot, with explicit field names, types, precision, and nullability—for example: asset code, trading pair, market type, latest price, quote currency, 24-hour price change, percentage change, 24-hour open, high, low, market cap, market cap rank, and update time. The contract should specify that prices use fixed-point or high-precision decimal arithmetic to avoid floating-point errors. Whether the percentage change is stored as a percentage value or a decimal ratio must be consistent across the entire pipeline. Public APIs should not add or remove fields arbitrarily: new fields must remain backward compatible, and field removals should go through a versioned migration.

    1. snapshot = {
    2. "asset_code": "ASSET_A",
    3. "pair": "ASSET_A/QUOTE",
    4. "market_type": "SPOT",
    5. "last_price": 0.0,
    6. "quote_currency": "QUOTE",
    7. "change_24h": 0.0,
    8. "change_pct_24h": 0.0,
    9. "open_24h": 0.0,
    10. "high_24h": 0.0,
    11. "low_24h": 0.0,
    12. "market_cap": 0.0,
    13. "market_cap_rank": 0,
    14. "updated_at": "ISO-8601"
    15. }

    2. The Data Model Should Separate Snapshots, Events, and Aggregates

    A market data system should not rely on a single “latest snapshot” table. A more reasonable model has three layers. The raw event layer records every ingested market change or periodic snapshot, preserving the source timestamp and an idempotency key. The normalized layer maps fields from different sources into the unified contract, completing the normalization of assets, trading pairs, and market types. The aggregation layer precomputes highs, lows, percentage changes, and rankings over minute or hour windows. The raw event layer supports auditing and replay, the normalized layer serves queries, and the aggregation layer powers low-latency display. This structure supports both real-time APIs and historical queries or incident reproduction.

    Storage selection should follow access patterns. The latest snapshot belongs in a low-latency cache with a short TTL, backed by the “last known good value” as a fallback. Historical detail fits a time-series database or columnar store, partitioned by time with a composite index on trading pair and timestamp. Global metrics such as market cap rankings can live in a relational database or a search-oriented store, updated in scheduled batches. Cache updates must follow “write to the database first, then invalidate the cache” or a message-driven update order, so that concurrent writes do not let stale values overwrite fresh ones. Updates for the same trading pair should carry a version number or update timestamp, and consumers should only accept data with a newer timestamp.

    3. Ingestion, Cleansing, and Consistency Validation

    The ingestion layer must handle rate limiting, timeouts, retries, and reconnection. Retries must be paired with exponential backoff and idempotency keys to avoid duplicate writes. The cleansing layer normalizes numeric precision, removes null values, standardizes trading pair casing, and checks whether timestamps are in the future or too old. Consistency validation should at minimum cover: prices must be greater than zero; the high must not be lower than the low; the latest price and the open must fall within the high-low range; market cap must not be negative; the market cap rank must be a positive integer; the update timestamp must not go backward; and the percentage change must agree with the price change and the baseline price within an acceptable tolerance. When anomalies are detected, the data should be flagged as suspicious rather than overwriting the last valid value, and an alert should be raised.

    1. function validate(s):
    2. if s.last_price <= 0: return "invalid_price"
    3. if s.low_24h > s.high_24h: return "invalid_range"
    4. if s.last_price < s.low_24h or s.last_price > s.high_24h:
    5. return "price_out_of_range"
    6. if s.open_24h < s.low_24h or s.open_24h > s.high_24h:
    7. return "open_out_of_range"
    8. if s.market_cap < 0: return "invalid_market_cap"
    9. if s.updated_at <= last_seen_time: return "stale_or_reordered"
    10. expected_pct = (s.last_price - s.open_24h) / s.open_24h * 100
    11. if abs(expected_pct - s.change_pct_24h) > EPS:
    12. return "pct_mismatch"
    13. return "ok"

    4. Indicator Calculation and Precision Handling

    Price change and percentage change are the indicators most prone to disputes. Engineering-wise, the formulas should be fixed on the server side, with the front end responsible only for display. If the open price is the baseline, the price change equals the latest price minus the open, and the percentage change equals the price change divided by the open, multiplied by the percentage factor. If the price from 24 hours ago is the baseline, the baseline price must be stored separately and the display copy must state the convention clearly. Calculations should use high-precision decimals to prevent binary floating-point from producing trailing errors at many decimal places. The display layer may truncate or round according to the asset’s precision, but the computation layer must not truncate early. For extremely low-priced assets, use significant digits rather than fixed decimal places to avoid displaying all zeros. Market cap rank changes should be computed over the same time window to avoid comparing data updated at different frequencies.

    5. Cache Layering and Real-Time Push

    Market queries typically feature high concurrency, low latency, and far more reads than writes. A layered strategy of “local cache + distributed cache + persistent storage” works well: the local cache serves the hottest trading pairs, the distributed cache holds the full set of latest snapshots, and persistent storage handles history and auditing. Cache keys should include the trading pair, market type, and quote currency, and values should carry the update timestamp and version number. Real-time push can use a long-connection protocol with topic-based subscription per trading pair, pushing incremental updates and periodically sending full calibration frames. Clients must handle reconnection, out-of-order messages, and duplicates, using the update timestamp or a sequence number to determine freshness. The server should enforce a maximum push frequency and a merge strategy to prevent high-frequency updates from causing jitter.

    6. Visualization, Alerting, and Observability

    The visualization page should display price, percentage change, high and low, market cap rank, and update time together, using colors, arrows, and status indicators to convey changes—without exaggerating or implying returns. Alerting rules should cover data delays, missing fields, inconsistent percentage-change conventions, sudden price jumps, and push disconnections, with warning and critical severity levels. Observability metrics include ingestion latency, processing latency, push latency, error rate, cache hit rate, data freshness, and reconnection counts. Logs should record the trading pair, version number, source timestamp, and validation result to support auditing. If deployed on Baidu AI Cloud, general-purpose capabilities such as object storage, message queues, caching, logging, and monitoring/alerting can be selected by category, but capacity and interface planning should be based on actual business metrics.

    7. Security, Compliance, and Deployment Recommendations

    The market data service should implement authentication, rate limiting, and auditing to prevent malicious scraping and abuse. Public displays should state the data source and update time, and market information must not be framed as investment advice or a promise of returns. For deployment, it is recommended to split ingestion, computation, query, and push into stateless services; use message queues to buffer traffic peaks; scale horizontally to increase throughput; and use canary releases to reduce change risk. Key fields should have regression tests and data-quality reports, with periodic comparisons of computation results across different time windows. Only by unifying the data contract, validation rules, caching strategy, and observability into one design can a market data system strike the right balance among latency, accuracy, and maintainability.