The problem
Coinread aggregated raw tickers from many exchanges, and the aggregated price fed downstream products and market-cap rankings. Exchanges can report zero or missing prices, distorted quotes on thin markets, or wrong symbol mappings, and one bad ticker could skew a coin's aggregate price and shift its rank. In a market-data product, that is a trust problem, not just a quality problem.
My role
I designed and built the outlier-detection service in Go, including the voting logic and all of the drivers. It sits between the raw-ticker service and the aggregation service: it examines every raw ticker and republishes only the ones it trusts. I also built most of the trust service with another engineer. It produces the scores that decide how much weight each exchange carries in the final price.
Approach
I made outlier detection its own microservice, so aggregation only ever sees filtered data. Every 60 seconds (or on demand for backfills) it:
- Pulls all raw tickers and skips the run if the dataset timestamp has not changed.
- Pre-validates each ticker: a missing symbol or a bad or zero USD price is marked invalid and treated as an outlier immediately.
- Fans out by symbol to a pool of four workers, enriching each symbol with rank, supply, and competitor data from the symbol service.
- Runs independent driver checks concurrently per symbol: standard drivers first, then must-pass drivers against the survivors only.
- Tallies the votes and republishes only the inliers, normalized, to the aggregation topic.
Each driver is a different way of detecting bad data, so they fail in different situations:
| Driver | Scope | What it flags |
|---|---|---|
| mad-gecko | Local (across exchanges) | Prices more than 10 median absolute deviations from the cross-exchange median; fails closed when prices are too uniform to measure. |
| median-price | Global (history) | Price more than 40% away from the symbol's 24-hour historical median. |
| rank-cutoff | Global | A candidate whose implied market cap exceeds that of a boundary ticker ranked 400 to 500. |
| rank-disruption | Global, optional must-pass | Market-cap rank drift beyond a tiered allowance: 5 places for ranks 1 to 20, up to 50 for ranks 151 to 400, unlimited above 400. |
| competitor-rank | Global, optional must-pass | Rank drift measured against the median rank of competing symbols. |
Decision rule: a ticker is an inlier if at least one driver allows it. The three rank-type drivers count as a single vote so they cannot outvote the statistical checks, and any enabled must-pass driver can veto a ticker unconditionally.
Trust scores: outlier votes decide which tickers survive, and trust scores decide how much each surviving exchange counts. A separate trust service scores exchanges and markets against reference exchanges such as Binance, Kraken, and Bitstamp, using order-book quality (bid/ask spread and depth within 2%, weighted 0.5) and website traffic (weighted 0.2). Each measure is the distance from the reference median in MAD units. The aggregation service turns a score into a discount rate (100 minus the score, cached for six hours) that scales each exchange's volume before the volume-weighted price is calculated. A currency's tickers stay blocked until its trust data has been calculated.
Challenges
- Failing safely: a driver error marks the item an outlier, and having no drivers marks everything an outlier. Bad data never leaks through, at the cost of dropping good data during a fault.
- Expensive rank checks: the rank drivers need a candidate price, which means an on-demand call to the aggregation service. I cached those results for 15 minutes by content hash, de-duplicated concurrent calls with singleflight, and cached symbol, ticker, and boundary-ticker lookups for five minutes.
- A leaking detector: a streaming anomaly detector (KS, diff, and CDF tests, flagging above 0.7 anomaly probability) leaked memory, so I disabled it rather than ship it. A historical-mean driver is also switched off.
- Too little data to judge: statistics across exchanges are meaningless for a coin on one exchange. Local drivers are skipped unless the symbol has at least two pairs and two exchanges.
- Explaining decisions: every run keeps per-symbol Prometheus counters for inliers, outliers, and invalid tickers, and can optionally produce an XLSX report so a surprising exclusion can be traced to the driver that caused it.
Results
- Overall data accuracy improved by 85%.
- Aggregation reads only the filtered set, so one misbehaving exchange can no longer skew a symbol's price or rank.
- Drivers, thresholds, and the must-pass rules are configurable, so tuning does not need a redeploy of the detection logic.
What I learned
Several cheap, independent checks that vote beat one clever detector, and a veto rule covers the cases where consensus is wrong. The stateful detector was the hardest part to run reliably, which is why I would start with simple robust statistics like median and MAD.