Real-Time Market Data Systems: Architecture Design and Engineering Practices

    Real-time market data powers trading across digital assets, securities, and commodities. This article explains how to build a low-latency, high-concurrency, fault-tolerant market data platform from an engineering perspective. It covers the business and technical characteristics that distinguish market data from ordinary workloads, then walks through a six-layer architecture: data collection with normalization and deduplication, a message queue for peak shaving and decoupling, time-series storage paired with in-memory caching, stream-based window aggregation for indicators such as 24-hour change and high/low prices, real-time push over long-lived connections with incremental frontend rendering, and consistency and fault-tolerance strategies. It also outlines observability metrics and capacity planning. Readers will gain a structured view of each layer's responsibilities and trade-offs, along with illustrative Python snippets for normalization, deduplication, and incremental aggregation.

    Real-time market data is widely used in trading scenarios across digital assets, securities, and commodities. Take a typical market snapshot as an example: it usually contains fields such as trading symbol, trading pair, last price, quote currency, 24-hour change amount and change percentage, open price, high price, low price, market cap, market cap ranking, and the data update time. A single record may look simple, yet behind it lies a complete system for data collection, transmission, computation, storage, and display. This article takes an engineering-practice perspective to explain how to build a real-time market data platform that is low-latency, high-concurrency, and fault-tolerant.

    1. Business and Technical Characteristics of Market Data

    Before designing the system, you must first clarify the core characteristics that distinguish market data from ordinary business data:

    1. Strong time-series nature: Every data point is bound to a millisecond-level or even finer timestamp, its value decays over time, and the latest value matters most.
    2. High frequency and bursts: Market sources push data continuously, and during sharp price swings both request volume and write volume can spike several times over within seconds, forming a classic “traffic spike.”
    3. High on both read and write: There is a massive volume of real-time writes as well as large numbers of concurrent reads targeting the latest price and historical candlestick (K-line) data.
    4. Snapshots and increments coexist: The frontend needs both snapshots like “current latest price” and historical series like “the most recent N candlesticks.”
    5. Latency-sensitive: The core value of a market data product lies in being “fast,” and end-to-end latency often must be kept within a few hundred milliseconds.

    These characteristics mean the system cannot simply apply a traditional request-response database architecture. Instead, it needs dedicated design oriented toward streaming and real-time processing.

    2. Overall Architecture Layers

    A mature market data platform can generally be split into six layers:

    • Collection layer: Connects to multiple data sources and handles the pulling or receiving of market data plus format normalization.
    • Transport layer: Uses a message queue or data stream to carry high-throughput data, achieving peak shaving, decoupling, and replayability.
    • Computation layer: Cleans, aggregates, and computes indicators over the streaming data.
    • Storage layer: Combines a time-series database with an in-memory cache to serve historical queries and real-time reads separately.
    • Service layer: Exposes query interfaces and real-time push channels externally.
    • Presentation layer: The frontend receives incremental data over long-lived connections and renders it efficiently.

    The key design points of each layer are expanded below.

    3. Data Collection Layer: Multi-Source Ingestion and Normalization

    Market data often comes from multiple upstream sources whose field names, units, precision, and time zones all differ. The collection layer needs to accomplish three things:

    • Normalization: Unify field names, quote units, precision (for example, keeping prices to a fixed number of decimal places), and the timestamp baseline (unifying everything to UTC milliseconds).
    • Deduplication and ordering: Data sources may contain duplicates or out-of-order entries, so idempotent deduplication is needed using sequence numbers or timestamps.
    • Heartbeat and disconnect detection: Set timeouts and reconnection policies for each connection to ensure data is not interrupted.

    Illustrative code (pseudocode, conveying the idea only):

    1. def normalize(raw):
    2. return {
    3. "symbol": raw["code"].upper(),
    4. "price": round(float(raw["last"]), 6),
    5. "open": round(float(raw["open"]), 6),
    6. "high": round(float(raw["high"]), 6),
    7. "low": round(float(raw["low"]), 6),
    8. "change_pct": round(float(raw["pct"]), 4),
    9. "market_cap": float(raw["mcap"]),
    10. "ts": parse_to_epoch_ms(raw["update_time"]), # normalize to a millisecond timestamp
    11. }
    12. def on_message(raw):
    13. record = normalize(raw)
    14. if is_duplicate(record): # idempotent dedup by symbol + ts
    15. return
    16. publish(record)

    4. Transport Layer: Using a Message Queue for Peak Shaving and Decoupling

    A message queue or data stream should be introduced between the collection layer and the computation layer to decouple them. Its value is reflected in three areas:

    1. Peak shaving: Facing spike traffic, the queue acts as a buffer to prevent the downstream from being overwhelmed by instantaneous writes.
    2. System decoupling: Collection speed and computation speed become independent of each other, so scaling one side does not affect the other.
    3. Replayability: Once messages are persisted over time, new computation logic can re-consume them from a historical position, making backfill and recomputation convenient.

    When choosing a partition key, it is recommended to use the trading identifier as the partition basis. This ensures that market data for the same instrument enters the same partition in order, simplifying subsequent state computation.

    5. Storage Layer: Division of Labor Between Time-Series Data and Caching

    Market data is a typical form of time-series data, and its storage selection should focus on:

    • High write throughput: Time-series databases are optimized for sequential writes, and their write cost is far lower than that of relational databases.
    • High compression ratio: Adjacent values in time-series data change little, and columnar compression can significantly reduce storage costs.
    • Time-based partitioning: They naturally lend themselves to day/hour partitioning and cleanup via expiration policies.
    • Downsampling: Historical data is pre-aggregated into minute-level, hour-level, and day-level series, balancing query performance against storage cost.

    For scenarios that require extremely low-latency reads, such as the “latest price,” an in-memory cache should be introduced to hold the latest snapshot so that the query interface does not have to reach through to the storage layer every time.

    6. Real-Time Computation: Windows and Indicator Aggregation

    Indicators such as the 24-hour change amount, change percentage, high price, and low price are essentially stream aggregation problems. A common approach is window computation:

    • Rolling/sliding windows: Maintain aggregated state over a fixed time span.
    • Incremental updates: When a new data point arrives, only update the affected aggregate values rather than recomputing everything.

    Illustrative aggregation logic:

    1. def update_aggregate(state, rec):
    2. state["last"] = rec["price"]
    3. state["high"] = max(state["high"], rec["price"])
    4. state["low"] = min(state["low"], rec["price"])
    5. # change_pct is computed from the baseline price 24h ago
    6. state["change_pct"] = (state["last"] - state["base_24h"]) / state["base_24h"] * 100
    7. # evict window data older than 24h
    8. evict_expired(state, now=rec["ts"], window_ms=24 * 3600 * 1000)
    9. return state

    In stateful computation, you must separate “state” from “processing logic” and take periodic state snapshots (checkpoints) so the system can recover quickly after a failure.

    7. Real-Time Push and Frontend Presentation

    To push market data to clients, the service layer typically uses long-lived connections (such as a full-duplex channel based on WebSocket), which significantly reduces latency and wasted requests compared with polling. The frontend needs to focus on:

    • Incremental rendering: Update only the changed fields, avoiding a full-table redraw.
    • Throttling and frame batching: Batch and merge high-frequency pushes, refreshing the interface at a fixed frame rate.
    • Backpressure handling: When the client cannot keep up, discard stale intermediate values and retain only the latest one.
    • Rendering performance: Use virtual scrolling for long lists to keep the DOM size under control.

    8. Consistency and Fault-Tolerance Design

    In a distributed environment, “at most once” delivery may cause data loss, while “at least once” delivery may cause duplicates. In engineering practice, a combination of “at-least-once delivery + consumer-side idempotency” is commonly adopted to approximate “exactly once” semantics in a simple and reliable way. In addition, the system should have:

    • Reconnection: The client carries the sequence number or timestamp of the last received data point so it can resume and backfill the missing portion after reconnecting.
    • Reconciliation: Periodically compare upstream and local aggregated results, correcting any deviations as soon as they are found.
    • Degradation strategy: Under extreme traffic, prioritize core fields such as the latest price and weaken non-critical indicators.

    9. Observability and Capacity Planning

    Once a real-time system is live, it must remain continuously observable. It is recommended to cover at least: end-to-end latency distribution, message backlog, consumption rate, write failure rate, and data freshness (the time gap between the newest data and the present), together with monitoring alerts. For capacity planning, load testing and headroom should be reserved separately for peak write TPS, peak concurrent connections, and storage growth rate.

    10. Summary

    A high-quality real-time market data system is essentially a layered engineering practice built around four goals: low latency, high throughput, strong consistency, and fault tolerance. The collection layer solves data normalization and ingestion; the transport layer uses a message queue for peak shaving and decoupling; the storage layer combines a time-series database with in-memory caching; the computation layer performs incremental aggregation via stream windows; and the service layer pushes data in real time over long-lived connections, ultimately rendered efficiently by the frontend. Understanding each layer’s responsibilities and key trade-offs is what lets you find the right balance among cost, performance, and stability for your own business.