Architecture Design and Implementation of a Financial Market Data Aggregation System
This article walks through the architecture of a financial market data aggregation system, covering a five-layer design that decouples ingestion, normalization, storage, computation, and distribution. It explains configuration-driven source field mapping, unit and timestamp alignment, incremental sync with idempotent writes, windowed real-time calculation of price change events, multi-level caching, and observability practices, along with common pitfalls to avoid. Readers will get a practical blueprint for building a stable pipeline that handles heterogeneous, high-frequency market and announcement data.
1. Requirements Background and Problem Abstraction
The source material is a typical morning financial briefing: major stock indexes all fell sharply, precious metal prices pulled back noticeably, one tech company announced a hardware form-factor innovation, and another raised the cap on its share buyback. For developers, this content is not the business goal itself. The real technical problem is: how to reliably collect, clean, compute, and distribute heterogeneous, high-frequency, inconsistently formatted market and announcement data to end clients.
Four core capabilities need to be abstracted:
- Multi-source ingestion: Field naming, time precision, and encoding differ greatly across sources.
- Normalization: Natural-language expressions such as “fell more than 2%” or “surged 17%” must be restored into computable structured values.
- Real-time computation: Metrics like change percentage, amplitude, and abnormal volume need windowed calculation.
- Reliable distribution: The push path must tolerate network jitter and consumer retries.
2. Layered Architecture
A five-layer structure is recommended, with clear contracts decoupling each layer:
- Ingestion layer: Handles protocol adaptation and rate limiting, hiding source differences.
- Normalization layer: Field mapping, unit unification, and time alignment.
- Storage layer: Hot data goes to an in-memory cache; warm and cold data lands in object storage and columnar files.
- Computation layer: Streaming jobs perform window aggregation and threshold evaluation.
- Distribution layer: A message queue handles fan-out and supports multiple client subscriptions.
On the cloud, these layers can map to general categories: object storage, message queue, container platform, log service, and monitoring/alerting. When selecting services, prioritize elastic scaling and pay-as-you-go billing, and avoid reserving resources long-term for peak traffic.
3. Data Source Adaptation and Field Normalization
The place where the ingestion layer most easily spirals out of control is when “more sources turn into an if-else hell.” A configuration-driven mapping table is recommended instead of hardcoding:
# Example: source field mapping configurationSOURCE_SCHEMA = {"src_a": {"price": "last", "change_pct": "pct_chg", "ts": "update_time"},"src_b": {"price": "close_px", "change_pct": "chg_ratio", "ts": "t"},}def normalize(raw: dict, source: str) -> dict:m = SOURCE_SCHEMA[source]return {"price": float(raw[m["price"]]),"change_pct": float(raw[m["change_pct"]]),"ts": normalize_ts(raw[m["ts"]], source),}
Three details must be handled:
- Unit unification: Some sources use yuan, others use cents; percentages are written as
0.02by some and2by others. Converge these in the normalization layer so downstream consumers no longer need to be aware of them. - Time alignment: Sources may have second-level or minute-level delays. Record both the collection timestamp and the source timestamp to support later data-quality attribution.
- Missing values and anomalies: Zero prices, change percentages outside a reasonable range, and inverted timestamps should go to an isolation queue rather than being dropped outright, ensuring traceability.
4. Incremental Sync and Consistency
Full pulls are prohibitively expensive in high-frequency scenarios. A practical compromise is “low-frequency full calibration plus high-frequency incremental catch-up”:
- Take a full snapshot every few minutes and write it to object storage as a baseline.
- Continuously append incremental messages, using a unique business key for idempotent writes.
- Periodically compare the baseline with the incremental aggregation result, and trigger an alert when the deviation exceeds a threshold.
The idempotency key design is critical. It usually combines “source + instrument identifier + time slot” to avoid duplicate consumption doubling the metrics.
5. Real-Time Computation and Anomaly Detection
The “fell more than 2%” and “surged 17%” in the source material are essentially threshold events. Use a streaming job to aggregate over fixed windows and then evaluate:
-- Example: aggregate change percentage within a windowSELECT symbol,first(price) AS open_px,last(price) AS close_px,(last(price) - first(price)) / first(price) AS chgFROM ticker_streamGROUP BY symbol, tumble(interval '1' minute);
Three engineering points to note: the window should not be too short, or noise will drown out the signal; the state backend needs periodic snapshots to support failure recovery; announcement-type text such as “buyback cap raised” or “form-factor innovation announced” should go through a separate text classification pipeline, computed apart from the numeric stream to avoid mutual blocking.
6. Caching Layers and Distribution
Read-heavy, write-light market queries suit multi-level caching: a local cache serves hot instruments, a distributed cache serves the full list, and the cache key carries a data version number for fast invalidation. On the distribution side, a message queue fans out by topic, and each consumer maintains its own offset to support resuming from a breakpoint.
7. Observability and Operations
Metrics that must be monitored: collection latency percentiles, normalization failure rate, isolation queue backlog, and computation job restart counts. Logs are collected centrally into a log service, with tiered thresholds set alongside monitoring and alerting. It is recommended to retain the original payload for each data-quality event to support post-mortem review.
8. Common Pitfalls
- Scattering normalization logic across the codebase, causing inconsistent definitions.
- Doing only real-time processing without calibration, so long-term accumulated deviation goes unnoticed.
- Lacking backpressure protection in the push path, letting downstream be overwhelmed at peak.
- Ignoring resource isolation between announcement text and numeric streams.
9. Summary
The difficulty of a market data aggregation system lies not in any single technology, but in unified definitions, idempotent reliability, and layered decoupling. Converge source differences in the ingestion and normalization layers, make computation and distribution independently scalable units, and pair them with a complete observability system to maintain stable output under traffic fluctuations. If built on the general cloud product capabilities of Baidu AI Cloud, prioritize elastic containers and managed message queues to reduce operational overhead.
