KatInterview

Designing a Data Integrity System for Multi-Store Order Data

System DesignModel answer
HardModel answerSystem Designfinancial systemsdata validationreconciliation

Last updated

Design a validation and reconciliation pipeline that enforces order-book correctness across a set of loosely coupled databases with different freshness guarantees.

Scenario

A trading platform ingests market data and internal order activity and fans it out into four stores:

  • Raw feed store — append-only log of every exchange message, keyed by venue, channel, session, and sequence number.
  • Normalized order store — one row per order lifecycle event in a canonical schema.
  • Execution store — records of trades and fills.
  • Analytics store — aggregated bars, snapshots, and derived metrics in a columnar format.

Each store is written by a different pipeline. They are eventually consistent with one another, not immediately so. Data quality regressions have been noticed: fill quantities that don't add up, sequence gaps that weren't flagged, and analytics snapshots that don't match the raw feed.

What you are asked to design

Walk through a complete validation and reconciliation system for this architecture. Your answer should cover:

  1. Invariants — What rules must always hold for orders, executions, and the live book? State them precisely enough that they could be turned into automated checks.

  2. Single-store validation — How do you enforce and detect violations within one store? Consider both schema-level constraints and batch analytical checks.

  3. Cross-store reconciliation — How do you compare stores that may be at different points in time? How do you distinguish "not arrived yet" from "genuinely lost"? What do you actually compare, and at what granularity?

  4. Edge cases — How does your approach handle partial fills, order replacements (modify/cancel-replace), out-of-order message delivery, duplicate messages, and reconnect replays from exchanges?

  5. Operationalizing it — How does the system surface problems? Think about alerts, dashboards, SLAs, and what a backfill looks like when a bug is found and fixed.

Be concrete: name the things you would compute, the comparisons you would make, and the thresholds or grace periods you would apply.

Hints

Hint 1

Start by defining the order lifecycle as an explicit state machine. Every invariant you care about either protects a state transition or enforces a numeric conservation law. Getting these written down precisely is more than half the answer.

Hint 2

Eventual consistency means a mismatch at time T might be fine by time T+10m. The design trick is watermarks: only compare a range once all stores declare they are complete through it. Define what 'complete' means per store, and define an SLA for how long a gap can stay in PENDING before it becomes an alert.

Hint 3

Don't diff billions of rows directly. Use order-independent fingerprints (e.g., sum of row hashes) bucketed by time and symbol, then recurse into finer buckets only where the fingerprints disagree. This is essentially a Merkle tree over time, and it makes drill-down cost proportional to the number of bad rows rather than total volume.