Designing a Real-Time Cryptocurrency Market Data System: Architecture and API Practices

    This article presents a practical architecture for building a reliable, low-latency cryptocurrency market data system. It covers snapshot and time-series data modeling, REST and WebSocket ingestion, rolling-window calculations, storage strategies, API design, frontend integration, monitoring, and data quality controls. The same principles can also be applied to stock, foreign exchange, and commodity market data systems.

    1. Background and Problem Definition

    Digital asset markets operate around the clock, experience significant price volatility, and generate frequent data updates. Whether you are building a quantitative trading strategy, a market dashboard, or a market data aggregation service, you face the same core challenge: how to acquire and process real-time market data reliably, accurately, and with low latency.

    A typical market snapshot, or ticker, contains key fields such as the trading pair, market type, latest traded price, quote currency, 24-hour price change and percentage change, opening price, high and low prices, market capitalization and rank, and the data update timestamp.

    This article outlines a general-purpose real-time market data architecture across five areas: data modeling, data collection, calculation logic, storage selection, and API design.

    2. Market Data Model Design

    Market data is essentially a time series of snapshots that changes over time. A practical model should distinguish between the current state and the historical record.

    1. Current snapshot: Describes the present market state of a trading pair, including the latest price, 24-hour high and low prices, and market capitalization. Because this data changes frequently and is often read by the frontend, it is well suited to key-value caching.

    2. Historical time series: Stores price sequences at fixed intervals, such as one-minute candlesticks. This data is used for chart rendering, backtesting, and statistical analysis.

    An illustrative data structure is shown below:

    1. {
    2. "symbol": "BASE-USDT",
    3. "market": "CRYPTO",
    4. "currency": "USD",
    5. "last_price": 0.05803,
    6. "open_24h": 0.05983,
    7. "high_24h": 0.06013,
    8. "low_24h": 0.05803,
    9. "change_24h": -0.0018,
    10. "change_pct_24h": -3.005,
    11. "market_cap": 27395600,
    12. "rank": 475,
    13. "ts": "2026-12-01T19:53:39Z"
    14. }

    Important design considerations include:

    • Store price fields as strings or fixed-point decimals to avoid floating-point precision loss.
    • Include timestamps in a consistent time zone in every snapshot.
    • Use a normalized base asset-quote asset format for trading pair identifiers, making cross-market aggregation easier.

    3. Data Collection: Choosing Between WebSocket and REST

    Market data is typically collected in one of two ways.

    1. REST polling: This approach is simple to implement and is suitable for low-frequency use cases, such as a ranking page refreshed every minute. However, latency is limited by the polling interval, and frequent requests may consume bandwidth without producing meaningful updates.

    2. WebSocket streaming: The data source actively pushes incremental updates to clients. Latency can generally be kept within hundreds of milliseconds, making WebSocket the preferred choice for real-time dashboards.

    In practice, a hybrid model is recommended: use REST to retrieve the full snapshot and WebSocket to receive incremental updates. When the service starts, it first obtains a complete snapshot through REST to establish a baseline, then continuously merges updates received through WebSocket.

    Example pseudocode:

    1. snapshot = rest_client.get_ticker("BASE-USDT") # Full baseline
    2. ws = WebSocketClient(on_message=handle)
    3. def handle(msg):
    4. if msg.type == "ticker":
    5. snapshot.apply_delta(msg.data) # Merge incremental data
    6. cache.set(f"ticker:BASE-USDT", snapshot)
    7. elif msg.type == "trade":
    8. snapshot.update_price(msg.price, msg.ts)

    The ingestion layer should also support automatic reconnection, heartbeat checks, message sequence validation, and deduplication. These mechanisms help prevent missing or out-of-order data caused by network instability.

    4. Core Calculation Logic

    4.1 Percentage Change

    The percentage change can be calculated as follows:

    1. Percentage change = (Latest price - Price 24 hours ago) / Price 24 hours ago × 100%

    The reference price is usually the opening price of a rolling 24-hour window rather than the opening price of the calendar day. The implementation must clearly define and consistently apply this rule.

    4.2 Maintaining High and Low Prices

    A rolling-window algorithm can be used to maintain the highest and lowest prices. The 24-hour price sequence can be stored in an ordered set or a ring buffer. Alternatively, the system can directly consume precomputed high and low values provided by the data source.

    4.3 Market Capitalization and Ranking

    Market capitalization is calculated as:

    1. Market capitalization = Circulating supply × Latest price

    Ranking requires a global sort. It is generally more efficient to calculate rankings periodically in batches on the server and write the results to a cache, rather than sorting the entire dataset for every request.

    5. Storage Selection and Time-Series Processing

    • Hot data: Store the latest snapshots in an in-memory cache, such as a Redis-style key-value store. Configure an appropriate TTL to support high-concurrency reads.
    • Cold data: Store historical candlesticks in a time-series database or columnar storage system, which is naturally suited to efficient aggregation over time ranges.
    • Message queues: Use a message queue between the ingestion and calculation layers to decouple the services. This helps absorb traffic spikes and allows consumers to scale independently, making message queue services a common component in cloud-based architectures.

    6. API Design and Frontend Integration

    External market data APIs should follow these practices:

    1. Provide a REST endpoint that returns snapshots, with stable field names and version management.
    2. Provide a WebSocket endpoint that allows frontend clients to subscribe to specific trading pairs. The server should manage subscriptions and apply push-rate limits.
    3. Return price changes as signed numeric values, such as -3.005%. The frontend can then apply the appropriate colors and visual styles, keeping data separate from presentation.
    4. Add rate limiting, circuit breaking, and fallback strategies at the API layer. If the upstream data source becomes unavailable, the service can return the most recent valid snapshot with its timestamp and clearly indicate that the data is delayed.

    7. Monitoring and Data Quality

    The reliability of a market data system depends on comprehensive observability. Key metrics include:

    • Data source heartbeats and message latency
    • Ingestion throughput
    • Snapshot freshness, measured as the time since the last update
    • Abnormal values, such as instantaneous price changes beyond a defined threshold

    Suspicious values should undergo secondary validation and trigger alerts when necessary. The system should also maintain complete audit logs to support reconciliation and data replay.

    8. Conclusion

    A robust digital asset market data system depends on several core design principles: a clear separation between snapshot and time-series data models, a hybrid ingestion architecture, rigorous rolling-window calculations, hot-and-cold storage separation, and APIs designed for high concurrency and graceful degradation.

    Once established, this general architecture can be adapted to other financial market data scenarios, including equities, foreign exchange, and commodities, providing a reusable technical foundation.