Real-Time Market Data Pipeline Design: Modeling, Ingestion, and Consumption
A practical guide to building robust real-time market data pipelines, using a crypto market snapshot as the starting point. It covers fixed-point price modeling, derived-field validation, timezone semantics, idempotent updates, batch merging and backpressure, multi-level caching, push channels with rate limiting, and data-quality observability. Readers will learn how to address precision, ordering, latency, and consistency issues in high-frequency market data systems.
1. Starting with a Market Snapshot
In financial data systems, a market snapshot is the most basic yet most easily underestimated data form. Below is a typical crypto asset market record (fields have been redacted and abstracted):
{"symbol": "S","pair": "SUSDT","marketType": "CRYPTO","name": "Sonic","lastPrice": 0.02867,"currency": "USD","change24h": 0.0005194,"changePct24h": 1.845,"openPrice": 0.02815,"high24h": 0.03065,"low24h": 0.02784,"marketCap": 130000000,"marketCapRank": 145,"updatedAt": "2026-11-24 14:41:39"}
The record looks simple, but it involves a series of engineering issues: numeric precision, time semantics, field consistency, update frequency, and consumption patterns. This article uses this snapshot as a sample to discuss how to design a robust real-time market data pipeline.
2. Field Modeling: Solving the “Number” Problem First
2.1 Prices Must Use Fixed-Point Numbers, Not Floating-Point Numbers
In the sample, the last price is 0.02867, the high is 0.03065, and the low is 0.02784. These values have inconsistent decimal places and relatively small magnitudes. If IEEE 754 double-precision floating-point numbers are used directly in calculations, classic errors such as 0.1 + 0.2 != 0.3 may occur and be amplified in order matching, clearing, risk management, and other scenarios.
A recommended approach is to convert values uniformly into fixed-point integers and use the minimum tick size as the scaling factor. For example, with a precision of 1e-8:
from decimal import Decimal, ROUND_HALF_UPPRICE_SCALE = Decimal("0.00000001")def to_fixed(value: str) -> int:"""Convert a price string to a fixed-point integer to avoid floating-point errors"""return int((Decimal(value) / PRICE_SCALE).to_integral_value(ROUND_HALF_UP))def from_fixed(value: int) -> Decimal:return Decimal(value) * PRICE_SCALE
This way, 0.02867 is stored as 2867000, and the change amount 0.0005194 is stored as 51940. Subsequent addition, subtraction, and comparison operations have no precision loss. Values are converted back to decimal strings only for final display or JSON serialization.
2.2 Percentage Change Should Be Derived, Not Trusted Directly
The sample gives a percentage change of 1.845%, a change amount of 0.0005194, and an open price of 0.02815. Verification by formula:
changePct = change24h / openPrice × 100%= 0.0005194 / 0.02815 × 100%≈ 1.8451%
This is basically consistent with the given value. From an engineering perspective, it is advisable to treat changePct24h as a derived field, compute it from change24h and openPrice at write time, and perform a tolerance check on the read side (for example, allow a rounding deviation of ±0.01 percentage points). Once the deviation exceeds the threshold, a data quality alert should be triggered rather than silently accepting the value.
2.3 Time Fields Need Explicit Time Zones and Semantics
updatedAt is 2026-11-24 14:41:39, without a time zone identifier. In a system deployed across regions, this is a typical hidden risk. Recommendations:
- The storage layer should use UTC timestamps uniformly (millisecond or microsecond integers);
- The transport layer should use RFC 3339 format with a time zone, such as
2026-11-24T14:41:39Z; - The display layer should format according to the user’s time zone.
At the same time, distinguish between “data generation time” and “data ingestion time.” Market data often involves network latency and batch merging. If only one time field is retained, key evidence will be missing when troubleshooting latency issues later.
3. Ingestion Pipeline: Idempotency, Ordering, and Backpressure
3.1 Implement Idempotent Updates with Version Numbers or Timestamps
Market data updates are a high-frequency write scenario, and duplicate and out-of-order messages are difficult to avoid. A common approach is to attach a monotonically increasing version number to each record (for example, a sequence number pushed by the exchange). The consumer side overwrites only when newVersion > currentVersion:
UPDATE market_snapshotSET last_price = ?,high_24h = ?,low_24h = ?,version = ?,updated_at = ?WHERE pair = ?AND version < ?;
If the number of affected rows is 0, the message is expired or duplicate and can be discarded directly. Compared with the two-step “read first, then write” operation, this conditional update is safer under concurrency.
3.2 Batch Merging and Backpressure Control
When the push rate from the market data source is higher than the downstream processing capacity, processing each message individually will cause queue buildup. Feasible strategies include:
- Window merging: Aggregate on the ingestion side within a fixed time window (for example, 200 ms), keeping only the latest snapshot for the same trading pair;
- Bounded queue: Use a capacity-limited queue. When the queue is full, drop the oldest data rather than blocking the producer;
- Observable drops: Count every drop in metrics to avoid hidden data loss that “looks normal.”
It is important to emphasize that the value of market data decays very quickly over time. It is better to drop stale data than to let latency continue to accumulate.
4. Consumption-Side Design: Cache, Push, and Rate Limiting
4.1 Multi-Level Caching and TTL Strategy
Market data queries have obvious characteristics: read-heavy, write-light, and concentrated hotspots. A two-level cache is recommended:
- Local cache: Keep the latest snapshot in-process with a TTL of seconds to handle high-frequency reads;
- Distributed cache: Store complete snapshots and historical points with a slightly longer TTL, serving as the backing layer when the local cache misses.
Cache updates should follow the order of “write storage first, then delete cache” to avoid dirty reads. For scenarios such as market data where brief inconsistency is acceptable, “write cache + asynchronous persistence” is also acceptable, but the data version in the cache must not go backward.
4.2 Push Channels and Rate Limiting
Push channels for terminals or frontend services need to handle many connections and complex subscription relationships. Common designs include:
- Maintain a subscription relationship table by trading pair, and push updates only to connections subscribed to that pair;
- Set a push rate limit per connection, for example, at most N messages per second, with excess updates merged into the latest value;
- Carry the “last version number” in heartbeat and reconnection mechanisms, so the server can replay or skip deltas accordingly.
The purpose of rate limiting is not to restrict users, but to protect the server from being overwhelmed by burst subscriptions or slow consumers. For slow consumers, prefer “overwrite-style push” (push only the latest value) rather than “queue-style push” (replay all historical values).
5. Observability: Making the Data Pipeline Explainable
Failures in market data systems often manifest as “wrong numbers” rather than “service unavailable.” Therefore, observability design should focus on data quality. At a minimum, collect the following metrics:
| Metric Category | Example Metric | Purpose |
|---|---|---|
| Timeliness | End-to-end latency P50/P99 | Determine whether the pipeline is congested |
| Completeness | Number of snapshots per unit time | Detect missed collection or stream interruption |
| Consistency | Failure rate of percentage-change validation | Detect data source anomalies |
| Drop rate | Number of records dropped due to queue overflow | Assess whether capacity is sufficient |
In addition, maintain a “last successful update time” record for each trading pair. If a trading pair has not been updated for longer than the expected interval, trigger an alert. Compared with global service health checks, this per-trading-pair check can better locate local problems.
6. Conclusion
A seemingly ordinary market snapshot involves multiple engineering points: fixed-point modeling, derived-field validation, time zone semantics, idempotent updates, backpressure control, multi-level caching, and data quality monitoring. Only by implementing these points systematically can a market data service remain stable and trustworthy in a real environment characterized by high frequency, out-of-order messages, and bursts.
When deploying such services on the cloud, general-purpose capabilities can help offload infrastructure burdens, such as using a message queue to handle ingestion-side traffic, object storage to archive historical snapshots, and logging and monitoring/alerting services to build an observability system. The key is to design the data model and pipeline semantics clearly; infrastructure is only the foundation that carries these designs.
