Latency and fairness
Measure by percentiles rather than averages, and decide by design what wins: speed or price.
Lesson 69 min
By the end of this lesson
- Calculate a median or a percentile by the nearest-rank method
- Define latency as the time between two passes through the gateway
- Compare IEX’s common delay and batch auctions with the race for speed
In this lesson4
"Our engine processes an order in 40 microseconds on average." The sentence reassures, and says almost nothing: neither what the slowest order goes through, nor whether all members are treated alike. What you will learn here: latency is measured as a distribution, by percentiles, and fairness between members is decided by market design, not by the speed of the machines.
Measuring from door to door
Latency
The time between a gateway receiving a message and the same gateway sending the response produced once the engine has processed it.
Writing for the time the gateway receives the message and for the time the same gateway sends the response, the latency is:
This is the measure the European regulation asks venues to monitor in real time (Delegated Regulation (EU) 2017/584, art. 13): from door to door, not just the engine's computation. A queue in front of the sequencer, slower logging, a garbage-collector pause: everything counts.
The average lies, percentiles tell
Ten measurementsFictional
Ten fictional orders, latencies in microseconds, sorted: 38, 40, 41, 42, 42, 43, 45, 47, 52, 950.
- Mean: (38 + 40 + 41 + 42 + 42 + 43 + 45 + 47 + 52 + 950) ÷ 10 = 1,340 ÷ 10 = 134 µs. No order took 134 µs.
- Median (50th percentile): at rank ⌈0.50 × 10⌉ = 5, i.e. 42 µs. Half of the orders go through in 42 µs or less.
- 90th percentile: rank ⌈0.90 × 10⌉ = 9, i.e. 52 µs.
- 99th percentile: rank ⌈0.99 × 10⌉ = 10, i.e. 950 µs. One order in a hundred, here one in ten, waits twenty times longer than the median.
That slow order is the costly one: by the time it enters, the book may already have changed.
Writing for the number of measurements, sorted in ascending order, and for the target percentile as a fraction (0.99 for the 99th percentile), the percentile is the measurement at rank :
/** Percentile by the nearest-rank method; measurements in whole microseconds. */
function centile(mesures: number[], p: number): number {
const triees = [...mesures].sort((a, b) => a - b)
const rang = Math.ceil((p / 100) * triees.length)
return triees[Math.max(0, rang - 1)]!
}
centile([38, 40, 41, 42, 42, 43, 45, 47, 52, 950], 99) // 950
With ten measurements, the 99th percentile is just the slowest. For it to mean something you need thousands: compute it over a whole session, or a load test (lesson 9).
Why can an engine announce a good average and still handle some orders badly?
Fairness, a matter of design
In continuous trading, the first one numbered is filled first. If two members target the same order, the one arriving a few microseconds earlier wins. That drives a speed race: closer machines, shorter networks.
Two real, public answers exist:
- The same delay for all. IEX, approved as an exchange by the SEC on 17 June 2016, sends every incoming message through a 61,625-metre coil of optical fibre, an equivalent latency of 350 microseconds, with no exception (SEC, order 34-78101).
- Batch auctions. Budish, Cramton and Shim propose replacing the continuous book with uniform-price auctions at short intervals, for example every tenth of a second: speed no longer pays, competition moves to price (Quarterly Journal of Economics, 2015).
The BVMAC runs the longest batch there is: one auction a day. Orders entered during the pre-opening, from 9:00 to 11:00, are matched together at 11:00 (BVMAC, session hours). Arriving at 9:01 rather than 10:59 does not change the price; only time priority between orders whose limit equals the price still matters (student track, The auction). The move to continuous trading the BVMAC is preparing will raise the question of speed.
arrival time (µs): 0 → 100
t = 0 µs
One sell, three buyers
Race or batch, same ordersFictional
A sell of 50 shares at 10,000. Three buys of 50 shares: "Fast" at 10,000 (arrived at 0 µs), "Medium" at 10,050 (40 µs), "Slow" at 10,100 (90 µs). Reference price 10,000.
Continuous: "Fast" is numbered first and takes the 50 shares at 10,000, i.e. 500,000 XAF. "Medium" and "Slow" rest in the book.
Batch: the four orders are matched at once.
- At 10,000: demand 150, supply 50, tradable 50.
- At 10,050: demand 100, supply 50, tradable 50.
- At 10,100: demand 50, supply 50, tradable 50.
- Tie at 50: keep the smallest unexecuted surplus, 0 at 10,100. "Slow" is filled, 50 × 10,100 = 505,000 XAF.
The seller receives 5,000 XAF more, and it was the price bid, not speed, that decided.
A shared clock
Fairness is also proven afterwards, through timestamps. In Europe, for high-frequency trading, the maximum divergence allowed from Coordinated Universal Time (UTC) is 100 microseconds, with a granularity of one microsecond or better (Delegated Regulation (EU) 2017/574).
No clock synchronisation requirement was found in CEMAC texts. The European figure is given as a benchmark; a 2025 proposal also plans to repeal this delegated regulation, and its final status has not been checked.
In the batch example, why is 10,100 chosen when all three prices allow 50 shares to trade?
Your turn
Read next: SEC, ordre 34-78101 approuvant IEX (2016)
A question? Ask your teacher, or an AI assistant, giving it the title of this lesson.