A General Architecture for US Stock Market Data Services: From Ingestion to Real-Time Push

    This article presents a vendor-neutral architecture for real-time stock market data services. It covers the core quote data model, price precision and timestamp conventions, and the calculation of price change and change percentage. The design combines push-based ingestion with polling fallback, data cleaning and validation, idempotent stream processing, tiered storage, REST query APIs, and WebSocket or SSE delivery. It also discusses rate limiting, reconnection, degradation strategies, freshness monitoring, reconciliation, and data quality assurance. The same approach can be adapted to FX, commodity prices, and other real-time quote scenarios.

    A General Architecture for US Stock Market Data Services: From Ingestion to Real-Time Push

    1. Background and Problem Definition

    In financial applications, market data is one of the most fundamental and critical data types. A typical individual stock quote usually contains the following fields: security name, trading symbol, market, currency, latest price, change amount, change percentage, and data update time. Although these fields appear simple, they involve a series of engineering problems, including data ingestion, real-time computation, consistency assurance, and low-latency distribution.

    This article focuses on how to build a general real-time market data service. It does not depend on any specific vendor product and only discusses industry-standard architecture patterns and engineering practices.

    2. Quote Data Model Design

    2.1 Core Field Abstraction

    A market quote snapshot can be abstracted into the following structure:

    1. {
    2. "symbol": "EXAMPLE",
    3. "name": "Example Company",
    4. "market": "US",
    5. "currency": "USD",
    6. "price": 1.39,
    7. "change": -0.04,
    8. "changePercent": -2.80,
    9. "timestamp": "2026-12-01T05:00:00Z"
    10. }

    Several design considerations apply:

    1. The combination of symbol and market must be unique: The same symbol may be listed in different markets, so market plus symbol must be used as the primary key.
    2. Transmit prices using fixed-point values or strings: Floating-point numbers can introduce precision errors during serialization and cross-language transmission. Internally, use fixed-point integers (for example, cents) or a high-precision decimal type.
    3. Use UTC timestamps with a time zone indicator: US equities involve pre-market and after-hours trading. Cross-time-zone handling is a common source of defects.

    2.2 Calculation Basis for Change and Change Percentage

    The change amount and change percentage are usually calculated based on the previous close:

    1. change = latest price - previous close
    2. change percent = change / previous close × 100%

    For example, if the latest price is 1.39 and the previous close is 1.43, the change is -0.04 and the change percentage is approximately -2.80%. Engineering requirements should explicitly define:

    • Division-by-zero protection: fallback logic when the previous close is missing or zero.
    • Precision rules: how many decimal places to retain and whether to use rounding or truncation. These rules must be consistent across the entire pipeline.
    • Previous-close adjustment rules for special cases such as trading halts, ex-rights, and ex-dividend events.

    3. Data Ingestion and Cleaning Layer

    3.1 Ingestion Modes

    Market data sources generally use two types of access methods:

    • Pull mode: Periodically poll an API to obtain snapshots. It is simple to implement but has limited real-time performance, making it suitable for low-frequency scenarios.
    • Push mode: Receive incremental quotes through long-lived connections or message subscriptions. It provides low latency and is suitable for scenarios with high real-time requirements.

    In practice, a common strategy is “push as the primary channel, with periodic polling as a fallback.” When the push stream is interrupted or has not updated for a long time, the system automatically degrades to polling calibration to prevent quotes from becoming stale.

    3.2 Cleaning and Validation

    Raw market data quality varies. Unified cleaning should be performed before persistence:

    1. Validity checks: Prices must be positive, and timestamps must not be significantly ahead of or behind the current time.
    2. Outlier filtering: If the price deviates beyond a threshold within a short period (for example, ±50%), mark the data as suspicious and route it to manual review or secondary confirmation. This prevents dirty data from polluting downstream systems.
    3. Deduplication and ordering: Deduplicate quotes for the same instrument by timestamp and ensure monotonic increase, avoiding the latest price from rolling back due to out-of-order data.

    4. Real-Time Computation and Storage Selection

    4.1 Computation Layer

    Real-time change calculation is well suited to a stream processing pipeline: market quote events are used as input, joined with static security reference data (name, market, currency, previous close), and then output as standardized quote snapshots. The calculation logic should be idempotent—processing the same event repeatedly should not produce different results. This is a prerequisite for failure recovery and replay.

    4.2 Storage Layer

    Different purposes require different storage forms:

    • Latest price cache: Use an in-memory key-value store to keep the latest snapshot for each instrument, enabling low-latency API reads.
    • Historical quote archive: Write to time-partitioned columnar storage or a time-series database to support candlestick aggregation and retrospective analysis.
    • Reference data store: Security metadata changes infrequently. Manage it in a relational database and periodically synchronize it to the cache.

    A practical principle is “hot data in memory, warm data in a time-series database, cold data in object storage,” balancing cost and performance.

    5. Service APIs and Real-Time Push

    5.1 Query API Design

    When exposing REST-style query APIs, consider the following:

    • Support batch queries, where one request contains multiple symbols, to reduce network round trips.
    • Include a data timestamp in the response so callers can judge data freshness themselves.
    • Cache high-frequency endpoints, for example for 1–3 seconds, trading a small amount of latency for a significant reduction in backend pressure.

    5.2 Push Channels

    For frontends or clients with high real-time requirements, WebSocket or SSE can be used to establish long-lived connections. The server pushes incremental updates according to subscriptions. Engineering considerations include:

    1. Rate limiting and coalescing: Under high-frequency quote updates, merge multiple updates for the same instrument within a short window into a single push to reduce client load.
    2. Heartbeat and reconnection: After a disconnect, the client automatically reconnects and pulls a full snapshot once to fill in missing data.
    3. Degradation strategy: When the push channel fails, the client automatically switches to short polling, prioritizing availability.

    6. Monitoring, Alerting, and Data Quality Assurance

    The core SLA of a market data service is “data freshness” and “accuracy.” Monitoring should focus on these two aspects:

    • Update latency monitoring: Measure latency percentiles from quote time to queryable time, and trigger alerts when thresholds are exceeded.
    • Data completeness monitoring: Monitor the update interval for each instrument. If there is no update for an extended period, excluding market-closed periods, trigger an alert automatically.
    • Reconciliation: After the daily close, compare closing prices with an authoritative data source. Automatically repair deviations and retain an audit trail.
    • End-to-end tracing: Tag each quote event to help locate where latency or loss occurs.

    7. Conclusion

    Building a reliable market data service depends less on a specific technology component and more on the systematic design of the data model, calculation conventions, quality validation, degradation strategies, and monitoring. Developers are advised to follow this path: first define a clear data contract and precision rules; then build a dual-channel ingestion layer with push and polling; pair it with idempotent stream processing and tiered storage; and finally close the loop with comprehensive freshness monitoring and reconciliation mechanisms. This general methodology also applies to foreign exchange, commodity prices, and other real-time quote scenarios.