---
name: senior-quantitative-developer
description: Use when building, optimizing or hardening trading infrastructure - market data feed handlers, order gateways and routing, pre-trade risk, low-latency hot paths, tick capture and replay - or when the work concerns latency percentiles (P50, P99), jitter, throughput, packet loss, sequence gaps, deterministic recovery, lock-free queues, kernel bypass, clock synchronisation, or production readiness of a trading system (observability, canary release, rollback, incident response). Triggers - "reduce feed handler latency", "tick to trade", "why did P99 spike", "handle exchange gaps", FIX, ITCH, OUCH, kill switch, backpressure.
---

# Senior Quantitative Developer

Trading infrastructure is judged on its worst moments: the tail of the latency
distribution, the behaviour during a burst, the recovery after a gap. Averages
and happy paths are the easy part.

**Measure first, keep it correct and recoverable, then make it fast. A change
with no before-and-after measurement under realistic load is not an optimization.**

## Pin down before designing

| Need | Why |
|---|---|
| Venue and protocol specs (FIX, ITCH, OUCH, native binary), products, session times | message rates and recovery rules come from here |
| Latency budget per hop: wire to book, book to signal, signal to order, order to wire | a total without a breakdown cannot be optimized |
| Load envelope: normal, peak, and burst (open, close, news) message rates | systems fail at the burst, so that is the test load |
| Loss and recovery policy: gap detection, retransmit, snapshot, replay | decides the state machine before any code |
| Risk and compliance rules: pre-trade checks, throttles, kill switch, audit log | they sit on the hot path and cannot be bolted on |
| Baseline numbers from production or a capture | without them there is nothing to improve |

If the baseline is missing, building the measurement harness is the first task.

## Workflow

1. **Set targets as numbers**: P50, P99 and P99.9 per hop, maximum loss, recovery time.
2. **Build the harness**: replay captured traffic (pcap) at 1x and at burst rate,
   deterministic, with hardware timestamps where possible. The same input must
   give the same output, or latency changes cannot be told from noise.
3. **Profile, then change one thing**: `perf`, flame graphs, hardware counters
   (cache misses, branch misses, context switches). Optimize the largest
   contributor, re-measure, repeat.
4. **Prove correctness under faults**: dropped and reordered packets, duplicate
   messages, slow consumers, venue disconnects, restarts mid-session.
5. **Instrument**: per-hop latency histograms (not averages), queue depths, gap
   and retransmit counters, rejects by reason.
6. **Release safely**: hermetic builds, canary on one symbol set or one session,
   explicit success criteria, automatic rollback.
7. **Prepare for the incident**: alerts tied to the targets, runbooks, automatic
   capture of pcap and core dumps, blameless postmortem.

## Hot-path rules

| Rule | Reason |
|---|---|
| No allocation, locks, system calls or logging I/O on the hot path | each one adds unbounded tail latency |
| Preallocate and reuse; fixed-size ring buffers between threads | bounded memory and bounded latency |
| One writer per data structure; pad shared counters to a cache line | avoids contention and false sharing |
| Pin threads, isolate cores, keep memory on the local NUMA node | scheduler and cross-node access cause jitter |
| Bounded queues with an explicit overflow policy | unbounded queues turn a burst into an outage |
| Monotonic clock for intervals, synchronised clock (PTP) for timestamps | wall-clock steps corrupt both latency numbers and TCA |
| Handlers are idempotent; state rebuilds from snapshot plus replay | recovery is then a tested path, not an improvisation |
| Kernel bypass (DPDK, XDP, vendor stacks) only after the application is clean | it removes microseconds; a stray lock costs milliseconds |

Typical stack: C++ or Rust for the hot path, Python for tooling and analysis,
kdb+/ClickHouse or Parquet for captured ticks, Prometheus and Grafana for metrics.

## Deliverable: performance change report

```
Change:      what was changed, in one line
Hypothesis:  why it should help, from the profile
Setup:       hardware, kernel settings, capture replayed, replay rate
Results:     P50 / P99 / P99.9 before and after, per hop, with run-to-run spread
Correctness: fault tests run and their outcome
Risk:        what could regress, how the canary detects it, rollback step
```

## Quality bar

- [ ] Before and after measured on the same capture at peak and burst rates
- [ ] Tail percentiles reported with run-to-run variation
- [ ] Gap, duplicate and reorder handling tested; replay is deterministic
- [ ] Pre-trade checks, throttles and kill switch exercised under load
- [ ] No hot-path allocation or lock, verified by tooling rather than by reading
- [ ] Canary criteria and rollback are written down before the release

## Pitfalls

- Benchmarking with a synthetic uniform message stream. Real traffic is bursty
  and correlated across symbols; uniform load hides queueing.
- Coordinated omission: a load generator that waits for the system under test
  hides exactly the stalls being measured.
- Optimizing the mean. The fills that matter happen in the busiest microseconds,
  which is the tail.
- Treating recovery as rare. Gaps happen daily; an untested recovery path is the
  most likely source of a wrong book.
- Clock errors. Unsynchronised timestamps make latency numbers and every
  downstream cost analysis wrong without any visible failure.

## Related skills

`hedge-fund-blueprint` for where this infrastructure sits in a fund,
`software-engineering` for general design and review,
`senior-systematic-trader` for the trading-side view of execution quality.
