Real-Time Processing and Presentation Practices for Digital Asset Market Data Snapshots

    Market data snapshots may appear as simple combinations of fields like latest price and change percentage, but in production, they demand low-latency delivery, historical traceability, cross-platform consistency, and extensibility. This article explores a universal data model and processing pipeline for digital asset market data, covering data modeling, real-time pipeline design, storage architecture, and frontend synchronization. It provides practical engineering practices to transform a basic display feature into a stable, operable system.

    Real-Time Processing and Presentation Practices for Digital Asset Market Data Snapshots

    Market data may seem like a simple combination of fields such as “latest price, change percentage, high, and low,” but in production systems, it must simultaneously meet requirements for low-latency display, historical traceability, cross-platform consistency, anomaly detection, and future extensibility. A seemingly simple market data snapshot often involves multiple stages: collection, normalization, validation, aggregation, caching, API publishing, frontend merging, and monitoring. This article centers on a typical market data snapshot, abstracts a universal data model and processing pipeline, and discusses how to elevate a system from “can display” to “can operate stably.”

    Note: This article focuses on market data engineering and does not constitute any investment advice. The asset codes, trading pairs, and values mentioned are structural examples and do not represent real market targets.

    1. Starting with Fields: Define Semantics Before Implementation

    Raw snapshots typically include: asset code, trading pair, market type, display name, latest price, quote currency, interval change amount and percentage, interval open price, high price, low price, market cap, market rank, and update time. To make these fields computable, comparable, and replayable, the first step is to clarify their semantics and precision.

    Field Category Typical Content Modeling Suggestions
    Identification Asset code, trading pair, market type Unify case and separators, establish an “internal instrument ID”
    Price Latest price, open price, high price, low price Use fixed-point decimals or decimal strings to avoid binary floating-point precision errors
    Change Interval change amount, change percentage Store original precision, unify rounding at the presentation layer
    Valuation Market cap, market rank Bind with circulating supply, statistical caliber, and instrument universe
    Time Update time Save event time, ingest time, publish time, and version number simultaneously

    It is recommended that the internal model contains at least the following information:

    1. {
    2. asset_code: "<internal asset code>",
    3. pair: "<asset>/<quote_currency>",
    4. market_type: "<market type enum>",
    5. display_name: "<display name>",
    6. last_price: "<decimal string>",
    7. quote_currency: "<quote currency>",
    8. change_amount: "<interval change amount>",
    9. change_pct: "<interval change percentage>",
    10. open_interval: "<interval open price>",
    11. high_interval: "<interval high price>",
    12. low_interval: "<interval low price>",
    13. market_cap: "<optional, unified valuation caliber>",
    14. market_rank: "<optional, unified instrument universe>",
    15. event_time: "<data source event time>",
    16. ingest_time: "<system ingest time>",
    17. publish_time: "<time published to read model>",
    18. source_seq: "<data source sequence number or internal version>",
    19. data_version: "<model version>"
    20. }

    Here, the event time represents “which moment the data belongs to in a business context,” the ingest time is used to troubleshoot pipeline latency, the publish time helps determine data freshness from the client’s perspective, and the version number handles out-of-order events and overwrites. If only one “update time” is retained, it becomes difficult to distinguish whether an issue is caused by data source latency, processing latency, or API caching.

    2. Change Metrics and Interval Indicators: Formula Consistency Over Field Completeness

    The change amount and change percentage must be bound to a clear baseline. If calculated based on the interval open price, the formula can be:

    1. change_amount = last_price - open_interval
    2. change_pct = (last_price / open_interval - 1) * 100%

    The open_interval must strictly match the window definition of the “past interval.” If displaying a “24-hour change,” the baseline price should be the open price corresponding to the 24-hour window prior to the current event time, not the natural day’s open price, nor the previous snapshot price. High and low prices should also come from the same window; otherwise, display contradictions like “latest price higher than high price” or “change percentage mismatching open price” will occur.

    The following constraints should be validated before storage and publishing:

    1. last_price > 0
    2. open_interval > 0
    3. low_interval <= high_interval
    4. low_interval <= last_price <= high_interval
    5. low_interval <= open_interval <= high_interval // Enable based on data source caliber
    6. change_amount approx last_price - open_interval
    7. change_pct approx (last_price / open_interval - 1) * 100

    Note that “approximate tolerance validation” should be used instead of absolute equality checks, as upstream sources may round differently. The system should store unrounded values and let the presentation layer unify decimal places according to currency or market rules. For low-liquidity assets, abnormal prices can cause metrics to fluctuate drastically. Therefore, independent price jump detection and manual review processes are necessary, rather than relying solely on formula validation.

    Market cap and ranking require additional explanation. Market cap usually equals price multiplied by circulating supply, but circulating supply may come from independent reference data. Ranking must be calculated within a clearly defined instrument universe at a unified timestamp. If every price update triggers a full rank recalculation, it is costly and prone to brief inconsistencies. A more robust approach is: update prices at high frequency, refresh reference data at low frequency, and publish the ranking read model as a whole by version. When displayed on the frontend, price, market cap, and ranking should all carry the same read version or a clear timestamp.

    3. Real-Time Pipeline: Collection, Normalization, Deduplication, and Aggregation

    A maintainable market data pipeline can be abstracted as: the collector receives data source pushes or periodic snapshots; the normalizer completes field mapping, type conversion, and unit unification; the validator performs checks for field completeness, numerical ranges, and time-series constraints; the deduplication and sorting module maintains the latest state by instrument and sequence number; the aggregator maintains interval statistics; and the read model is published to APIs and long-connection services.

    1. Normalization

    1. function normalize(raw):
    2. eventTime = parseTime(raw.update_time, timezone = "UTC")
    3. return {
    4. pair: canonicalPair(raw.asset_code, raw.quote_currency),
    5. marketType: normalizeMarketType(raw.market_type),
    6. last: decimal(raw.last_price),
    7. openInterval: decimal(raw.open_interval),
    8. highInterval: decimal(raw.high_interval),
    9. lowInterval: decimal(raw.low_interval),
    10. eventTime: eventTime,
    11. ingestTime: now(),
    12. sourceSeq: raw.sequence
    13. }

    The normalization stage should handle differences in case, separators, time zones, amount precision, and percentage units. For example, the change percentage might be expressed as 3.856 or 0.03856. This must be unified at the entry point; otherwise, magnitude errors will occur in subsequent calculations.

    2. Deduplication and Out-of-Order Processing

    If the data source provides a sequence number, it should be prioritized to determine recency. If not, a composite sorting key composed of event time, ingest time, and internal version number can be used. However, you must accept the reality that “it is impossible to perfectly determine the global order,” and keep a short out-of-order buffer in the read model.

    1. function onTick(tick):
    2. if not validate(tick):
    3. recordInvalid(tick)
    4. alertIfAbnormal(tick)
    5. return
    6. if isDuplicate(tick.pair, tick.sourceSeq):
    7. return
    8. current = latestCache.get(tick.pair)
    9. if current != null and tick.sourceSeq <= current.sourceSeq:
    10. recordOutOfOrder(tick)
    11. return
    12. latestCache.put(tick.pair, tick)
    13. publishToAggregator(tick)

    Deduplication cannot rely solely on the latest price, as the same price may correspond to different times. Out-of-order events should not all be discarded: the latest state can ignore old events, but historical archives should retain raw events for subsequent replay and auditing.

    3. Interval Aggregation

    For high-frequency data, it is not recommended to scan all historical events to calculate interval highs and lows on every update. Pre-aggregation can be done by minute or finer granularity, and window buckets can be combined to form the target interval:

    1. bucket_1m = {
    2. pair: ...,
    3. minute: floor(eventTime / 1m),
    4. open: first_event_price,
    5. close: last_event_price,
    6. high: max_event_price,
    7. low: min_event_price,
    8. seq_min: ...,
    9. seq_max: ...
    10. }
    11. rolling_interval = fold(
    12. buckets covering [eventTime - interval, eventTime],
    13. current_partial_bucket
    14. )

    Aggregation results should primarily rely on event time and record watermarks. If late data falls outside a closed window, it should be written to a correction queue and update the read model only after passing policy validation. It should not directly overwrite published results, as this would cause unexplainable jumps for users.

    4. Storage and Read Models: Separating “Latest” and “Historical”

    Market data systems typically face two types of read operations simultaneously: high-concurrency, low-latency access for “current latest prices,” and queries for “historical intervals and audit playback.” These two should not share the same storage structure.

    Latest snapshots are suitable for low-latency key-value caches, where the key consists of market type, trading pair, and read version. Historical events enter time-series storage partitioned by date, market type, and trading pair. Minute-level aggregate tables are used for quick queries of interval highs, lows, and trends. Raw events enter immutable archives for issue localization and replay. If using standard cloud infrastructure, you can combine general capabilities like key-value caches, message queues, time-series databases, object storage, logging services, and monitoring/alerting without binding business logic to a single component.

    Index design should revolve around common queries:

    1. Query current snapshot: market_type + pair
    2. Query historical interval: market_type + pair + time_range
    3. Query ranking list: universe_version + rank_time + market_type
    4. Query abnormal events: pair + event_time + error_code

    Read models should support versioned publishing. If a list page simultaneously displays price, market cap, and ranking, they should ideally come from the same version or the same refresh batch. This prevents users from experiencing a split-brain state where “the price has updated, but the ranking is still the old value.”

    5. API and Frontend Merging: Clarify Snapshots, Increments, and Freshness

    External APIs can be divided into snapshot queries, historical queries, and long-connection pushes. Snapshot responses should return at least the latest fields, event time, ingest time, data version, and a stale flag. Long-connection pushes should first send a full snapshot, followed by versioned incremental updates.

    1. snapshotResponse = {
    2. pair: "<trading pair>",
    3. data: { ...read model fields... },
    4. version: 10231,
    5. eventTime: "...",
    6. ingestTime: "...",
    7. stale: false
    8. }
    9. incrementalEvent = {
    10. pair: "<trading pair>",
    11. version: 10232,
    12. changed: { lastPrice: "...", changePct: "..." }
    13. }

    When merging data on the frontend, three rules should be followed: only accept increments with higher version numbers; refetch the snapshot if a version jump is detected; and display a “data delayed” status based on event time or server-side flags. Price flashing, animations, and sorting changes should be throttled to avoid page jitter caused by high-frequency refreshes. After a reconnection, do not assume previous data is still complete; resync the snapshot and verify the version.

    6. Quality Monitoring: From “Viewable” to “Diagnosable”

    The product quality of market data can be measured across several dimensions:

    • Freshness: Latency distribution from event time to publish time, observed by percentiles rather than just averages.
    • Completeness: Null rate for required fields, number of unmapped instruments, and ratio of events rejected by validation.
    • Consistency: Low/high price constraints, change percentage recalculation variance, and caliber consistency among market cap, price, and circulating supply.
    • Ordering: Duplicate rate, out-of-order rate, number of sequence gaps, and number of correction events.
    • Availability: API success rate, reconnection rate, cache hit rate, and ratio of stale version reads.
    • Business Anomalies: Short-term price jumps, drastic ranking changes, and sudden changes in the instrument universe count.

    Each type of anomaly should have an executable remediation action. For example, missing fields can degrade the display by hiding that instrument; if freshness exceeds a threshold, the API should return a stale flag; if ranking calculation fails, the old version can be retained while an alert is logged; batch correction events should be replayed and verified before publishing.

    7. Implementation Checklist

    1. Are field semantics fully documented, and are event time, ingest time, and version numbers traceable?
    2. Are prices and percentages using fixed-point decimals or decimal strings, and is display rounding unified?
    3. Do change amount, change percentage, and interval highs/lows use the same window definition?
    4. Are there strategies for deduplication, out-of-order processing, and late data correction?
    5. Are the latest snapshots, historical events, minute aggregates, and raw archives layered?
    6. Does the API return data version, update time, and stale flags?
    7. Does the frontend handle version jumps, reconnections, and stale data rollback?
    8. Are monitoring mechanisms established for freshness, completeness, consistency, ordering, and business anomalies?
    9. Is it possible to replay from raw events to verify that the read model can be rebuilt?
    10. Are compliance requirements such as data authorization, display caliber, and risk warnings clearly defined?

    In summary, the value of a market data snapshot lies not in a single number, but in “clear definition, consistent calculation, traceable updates, and discoverable anomalies.” By implementing these engineering constraints, the system will avoid constant rework caused by field semantic drift and pipeline coupling when expanding to support more market types, adding multi-source comparisons, enabling historical playback, or building ranking lists.