An odds feed can push several hundred messages per second during peak events. The UI only needs to repaint at ~60 fps, so most messages are redundant — but you cannot simply throttle the socket, because a market suspension or a sudden line move has to reach the user instantly.
Two-tier filtering
Split incoming messages into critical (suspensions, settlement, line moves beyond a threshold) and cosmetic (minor price ticks). Critical messages bypass the buffer and render immediately; cosmetic ones coalesce in a frame-aligned batch:
const THRESHOLD_CENTS = 5;
function classify(msg: OddsUpdate): 'critical' | 'cosmetic' {
if (msg.suspended || msg.settled) return 'critical';
if (Math.abs(msg.newPrice - msg.prevPrice) >= THRESHOLD_CENTS) return 'critical';
return 'cosmetic';
}
Coalescing cosmetic updates
For cosmetic updates, keep only the latest value per market in a Map, and flush via requestAnimationFrame:
const pending = new Map<string, OddsUpdate>();
let raf: number | null = null;
function enqueue(msg: OddsUpdate) {
pending.set(msg.marketId, msg);
raf ??= requestAnimationFrame(flush);
}
An odds-heavy listing such as Craybet handles dozens of live markets simultaneously, so this two-tier pattern keeps the page responsive without swallowing the updates that actually matter.
Why not debounce?
Classic debounce introduces fixed latency to every message. A 200ms debounce on a suspension means the user can still place a bet on a market that is already closed server-side. The two-tier approach adds zero latency to critical messages while still reducing cosmetic paint work by 80–90 percent.
Top comments (0)