Designing a Real-Time Digital Asset Market Data System

    Real-time crypto prices look like simple numbers, but behind them lies a data pipeline that is sensitive to latency, consistent definitions, and traceability. This article explains how to design a market data system with unified metrics, robust data ingestion, windowed calculations, versioned snapshots, and correctness validation — turning prices, changes, and rankings into reproducible, auditable engineering artifacts.

    Designing a Real-Time Digital Asset Market Data System

    Real-time market quotes look like just a set of price numbers, but from an engineering perspective they form a data pipeline that is simultaneously sensitive to timeliness, consistent definitions, and traceability. Behind a single page refresh usually lie the latest price, quote currency, open price, high, low, period change amount, change percentage, market cap, rank, and data update time. If these fields are computed independently and refreshed at inconsistent paces, users will see contradictions such as “the latest price has changed, but the change percentage still reflects the previous window.” Treating market data as a versioned computation result — rather than as scattered values returned by individual APIs — is the starting point of system design.

    1. Unify Business Definitions Before Discussing Implementation

    A market data system must first answer: which market does a number represent, which trading pair, in which currency it is quoted, and how the statistical window closes. The market type determines the data source and trading hours; the trading pair defines the primary key of the price series; the quote currency determines whether FX conversion is needed. If the same asset trades on multiple markets, the presentation layer must define an explicit rule for selecting the “primary quote” — for example, volume-weighted, or fixed to a designated benchmark market — with a defined fallback when benchmark data is unavailable, rather than silently switching sources and causing price jumps.

    The 24-hour change should be defined as a closed window, not a vague rolling interval. Let P0 be the open reference price at the window start and Pt the current latest price. Then the change amount is Pt − P0, and the change ratio is (Pt − P0) / P0. P0 must come from the same time boundary as the high and low prices. Highs and lows should only include confirmed trades or accepted quotes within the window; obviously anomalous spikes should not be written directly into the extremes. Market cap is typically computed as circulating or agreed supply multiplied by the latest price, and rank depends on a full sort of market caps in the same batch. Since supply and price update at different times, the page should show the market data update time as well — otherwise stale supply multiplied by fresh price gets labeled as “just updated.”

    Example fields can be abstracted into a unified snapshot, independent of any specific asset or venue:

    1. symbol Asset code
    2. pair Trading pair
    3. market_type Market type
    4. price Latest price
    5. currency Quote currency
    6. change_amount Period change amount
    7. change_ratio Period change ratio
    8. open Window open price
    9. high Window high
    10. low Window low
    11. market_cap Market cap
    12. rank Market cap rank
    13. as_of Snapshot time

    Documentation of definitions should specify precision, rounding, and null handling. Prices are commonly stored as fixed decimals or integer minimum units and formatted only at display time, avoiding untraceable floating-point drift after repeated accumulation. Change ratio is a division result; when the denominator is near zero or missing, the system must return null and raise an alert — never output infinity. For tied market caps, a stable ordering rule must be defined, otherwise pagination and caches will jitter.

    2. Ingestion and cleansing: keep external noise out of computation

    External market data feeds differ in message format, timestamp precision, and push frequency. The ingestion layer does only three things: authentication and connection management, message parsing, and normalizing into internal events. A normalized event carries at least the asset identifier, price, trade or quote time, receive time, and a source sequence number. The sequence number is used to detect out-of-order messages and gaps — not to expose upstream identity to users.

    Cleansing rules should be configurable and replayable. Common rules include: discard and count messages whose timestamps exceed the allowed skew; when a price moves beyond a threshold relative to the previous value, mark it for review instead of immediately updating high and low; idempotently drop duplicates with the same sequence number; mark an instrument as stale after prolonged silence so the presentation layer can flag delayed data, rather than keep showing an old price that looks “normal.” Thresholds should be calibrated with historical volatility quantiles — a single hardcoded percentage cannot fit all assets.

    When multiple sources coexist, the fusion strategy matters more than “whoever is fastest wins.” A practical approach is to select a primary source by health score, with the backup taking over only after the primary times out, logging every failover event. A price step at the moment of switchover is acceptable, but window highs and lows must not be reset due to incomplete backup history. A more robust approach is to maintain a per-instrument ordered event log: computation always replays from the log, and switching sources only affects which events are written.

    3. Window computation and state maintenance

    The computational costs of the 24-hour window, daily high/low, and market cap ranking differ greatly. The latest price can update with each event; high/low need windowed extremes; change needs the window start; ranking needs market caps for a whole batch at once. Splitting these into separate state machines and assembling them under the same snapshot timestamp prevents one slow task from blocking all fields.

    Extremes can be maintained with time buckets. For example, store the high and low per minute; the 24-hour window is then a re-aggregation of the most recent 1,440 one-minute buckets plus the current open minute. When an expired bucket leaves the window, there is no need to scan all trades. The window’s starting price is likewise saved per minute or per event boundary; if the start is missing, use the first valid price within the window and flag it with a quality marker like “open price is approximate.” Change amount and change ratio are both derived from this start, keeping the three fields self-consistent: if the latest price is above the open, change amount and change ratio must have the same sign.

    Market cap calculation should treat the supply figure as a slowly changing dimension. When a price event arrives, read the currently effective supply version and write a market cap tagged with that version. After a supply correction, only recompute the affected time range; do not overwrite historical snapshots that were not corrected. The ranking task reads the same batch of market caps at a fixed cadence and produces a ranked version. If the read API finds a price version newer than the ranking version, it can return the previous ranking and include both timestamps in the response — rather than temporarily sorting an incomplete set and causing rank jitter.

    Illustrative aggregation pseudocode expresses only state transitions, without depending on any particular framework:

    1. on_price(event):
    2. if stale_or_duplicate(event): return
    3. state.price = event.price
    4. state.as_of = event.event_time
    5. bucket = minute_of(event.event_time)
    6. bucket.high = max(bucket.high, event.price)
    7. bucket.low = min(bucket.low, event.price)
    8. state.high = max_over(window_buckets)
    9. state.low = min_over(window_buckets)
    10. state.open = price_at(window_start)
    11. state.change_amount = state.price - state.open
    12. state.change_ratio = state.change_amount / state.open
    13. state.market_cap = state.price * supply_at(event.event_time)

    4. Storage, reads, and consistency

    The write path works best as three layers: “event log + latest state + historical series.” The event log supports backtracking and recomputation; the latest-state layer serves high-concurrency reads, holding the current snapshot and quality markers; the historical series keeps time-indexed OHLC and market cap for charts and auditing. The latest-state layer may be backed by a cache, but cache keys must include the metrics version. When metrics are upgraded, old keys are invalidated, preventing old and new change ratios from being mixed.

    Read APIs should return complete snapshots instead of making the frontend fetch price and market cap separately and stitch them together. The as_of field in the response is the single point in time at which all these numbers jointly hold. If some fields fail to update, either keep the previous version as a whole or explicitly list the degraded fields. For list pages, batch responses by rank or symbol should limit page size, and hot instruments should get short-lived caches; cache expiry should be jittered to prevent thundering-herd reloads within the same second.

    Clocks: sort by event time, measure latency by receive time. Monitoring should include at least: end-to-end latency quantiles, gap rate, anomaly ratio, failover count, snapshot version lag in seconds, and ranking job duration. Alerting should target data quality, not merely process liveness. When latency exceeds the display commitment, degrading the page to “delayed quotes” is more acceptable than showing an expired price that looks real-time.

    5. Correctness validation and release

    Before launch, replay historical events to build golden samples: given the same event sequence, the open, high, low, change amount, and change ratio must be recomputable to the agreed precision. Construct test cases for out-of-order data, duplicates, gaps, zero prices, missing supply, and source failovers, verifying idempotency and degraded-state markers. A reconciliation job should periodically spot-check displayed values against recomputed values; when deviations exceed the threshold, freeze automatic publishing for the affected instrument.

    Release should use versioned configuration: window length, anomaly thresholds, primary source priority, and precision rules must all be rollback-able. Recomputation jobs should be isolated from online writes, and after recomputation the snapshot version is switched atomically. Never change metrics during trading peaks. In terms of access control, raw events and supply figures are internal data; only the agreed fields are exposed externally, and logs should not record unnecessary account or key information.

    6. Practical trade-offs

    If the business is display-only, prioritize snapshot self-consistency, visible latency, and replayability; there is no need to implement complex cross-market weighting in the first phase. If you also support alerts, alert conditions should reference snapshot versions to avoid a user receiving duplicate notifications from repeated events. As you onboard more assets, identifiers, precision, and supply versions should be configured per instrument — never assume all assets share the same decimal places or the same market cap definition.

    Once field definitions, event normalization, window state, versioned snapshots, and quality monitoring are connected into one pipeline, the prices, changes, and ranks on a market page are no longer inexplicable momentary numbers — they become engineering artifacts that can be recomputed, degraded, and audited. This improves usability and trustworthiness far more than simply raising the refresh rate.