Market Data Pipeline Resilience
Building a reliable market data pipeline requires an async-first design with layered fallbacks and rigorous testing for cache coherency and data integrity.
Key takeaways
- Design the fallback path before the primary integration, because the fallback is what runs during the incident.
- Never synthesize a missing bar. A reported gap is recoverable; a fabricated candle silently corrupts every indicator computed from it.
- Separate streaming from polling and put a filter between the stream and its consumers so a burst cannot flood the system.
- Cache coherency between an in-process cache and a shared one is a correctness property that needs its own tests.
- Pin down the exact return type of each data accessor in documentation; wrapper-versus-dataframe confusion is a persistent bug source.
To build a reliable market data pipeline from multiple providers, adopt an async-first architecture with native async methods that directly call the primary provider and seamlessly fall back to secondary sources via an executor upon failure. Layer caching and meticulously test data integrity, especially against fabricated bars.
What went wrong
Our automated trading system experienced a critical failure during a period of high market volatility when our primary real-time market data API experienced an outage. The system, designed to ingest tick and aggregate data, froze, leading to missed trading opportunities and, more critically, a cascade of stale data being processed by downstream analytical components. The core issue was not the primary provider's failure itself, but the system's inability to gracefully handle the interruption and provide a consistent, albeit potentially degraded, data stream. The cost was measured in lost alpha and the significant engineering effort required to diagnose and rectify the data flow.
Why it happens
Market data providers, regardless of their service level agreements or perceived reliability, will eventually fail. These failures can stem from a multitude of reasons: infrastructure issues, upstream data source problems, network disruptions, or even planned maintenance that wasn't communicated effectively. Furthermore, the complexity of real-time data ingestion, involving multiple independent streams like websockets for bars/trades and news, and pollers for regulatory filings, creates numerous potential points of failure. Each stream has its own failure mode, and a burst of data on one stream can overwhelm consumers if not properly filtered. Caching, while essential for performance, introduces its own challenges; cache coherency between distributed processes is not an inherent property and requires explicit validation.
What we changed
We re-architected our market data layer to be async-first. This means our primary provider is called directly using native async methods. When this primary connection fails, our system automatically falls back to a secondary source through an executor. This fallback mechanism is not a single point of truth; we utilize a diverse set of secondary and complementary providers. These include a free historical data source, a news and fundamentals API, a macro series API, and a regulatory filings feed. Each of these has its own distinct failure characteristics, which we've mapped and accounted for in our fallback logic.
Our real-time data flow is now managed through three independent streams: a bars and trades websocket, a news websocket, and a filings poller. Crucially, events from these streams pass through filters before being dispatched to consumers. This prevents a sudden burst of activity on one stream from flooding the entire system. This filtering is essential for maintaining stability.
Caching has been implemented in layers. We utilize a shared cache when available, and an in-memory cache when the shared cache is not accessible. This layered approach necessitates rigorous testing to ensure cache coherency between different processes, as it's not a property that can be assumed.
A significant change was how we handle historical data access. Our historical accessor now returns a wrapper object, not a raw dataframe. Initially, treating this wrapper as a dataframe was a recurring source of bugs. We've since documented the analyzer inputs per method to prevent this class of errors. The most critical failure mode we guard against is the synthesis of fabricated bars. A fallback that creates a "fake" candle to fill a gap, rather than reporting the gap, will silently corrupt every downstream indicator and trading signal.
How to check your own system
- Provider Failure Simulation: Manually disconnect or simulate failures for each of your market data providers (primary and secondary). Observe how your system reacts. Does it fall back gracefully? Are there any unhandled exceptions?
- Data Integrity Check: After a simulated failure and recovery, compare the data received from your system against a known good source for the period of the outage. Pay close attention to any gaps or anomalies in bars and trades.
- Cache Coherency Test: If you have distributed caching, implement tests that verify data consistency across different instances of your application after cache updates and invalidations.
- Stream Flood Test: Inject a high volume of data into one of your real-time streams (e.g., news websocket) and verify that other streams and consumers are not negatively impacted.
- Wrapper Object Usage: Review your code that consumes historical data. Ensure you are not treating any data access wrapper objects as raw dataframes without explicit conversion and validation.
Disclaimer
This article describes engineering decisions in a trading system. It is not investment advice. Trading involves substantial risk of loss and is not suitable for all investors. Past performance does not guarantee future results. Always do your own research and consider your financial situation before trading.
Frequently asked questions
What is the most reliable market data API?
- Reliability is better treated as an architecture property than a vendor choice. Every provider has outages, rate limits and coverage gaps, so the durable answer is a primary source with an independent fallback, explicit gap detection and a cache that can serve stale data with a known age rather than failing outright.
How do you detect missing market data?
- Compare the bars you received against the bars the trading calendar says should exist for that interval, and record the gap rather than filling it. Gap detection has to be an explicit step, because most client libraries return a shorter series without signalling that anything is missing.
Should a trading bot use free market data?
- Free sources are viable for research, end-of-day work and as a fallback, but they typically lack the latency guarantees, corporate-action handling and rate limits that live intraday trading needs. A common arrangement is a paid primary for execution decisions and a free secondary for backfill and cross-checking.
Related Topics
Tradewink builds explainable market research for self-directed traders. Build a watchlist, inspect signal reasoning and risk context, and paper-track ideas before you decide. Live broker workflows are invite-only when available.
Put this knowledge to work
Tradewink uses AI to scan hundreds of stocks daily and delivers trade ideas with full signal breakdowns — free to start.
Save a signal preview for later
Get a concise AI signal example in your inbox, then build a watchlist when you are ready. No spam, unsubscribe anytime.
Start with free AI trade ideas
See how Tradewink turns market structure, momentum, and risk rules into trade-ready signals. Free to start, with your broker staying in control.
More in Engineering Learnings
Measuring Missed Exit Profits
Quantify exit strategy performance by tracking Maximum Favorable Excursion (MFE) and Maximum Adverse Excursion (MAE) against realized profit and stop.
Read articleDetecting Market Regime Changes
We detect market regime changes using a dual-clock system: a daily Hidden Markov Model for broad market classification and an intraday efficiency ratio…
Read articleSecurely Storing User Broker API Keys
A data-driven approach to securing user broker API keys, detailing a production incident and the implemented safeguards.
Read article