Skip to Content
PredictorSDK

Matching reads each new snapshot in as soon as it is published

The API now reads every new matching snapshot, and refreshes its copy of today's finished games, in the background as they are published, so a matching list request no longer waits for them, even from a caller who asks only about once a minute.

Fix

Matching publishes a new snapshot about every 12 seconds, and the API has to read each one into memory before it can answer from it. Until now it did that when a request asked. Earlier today a request that arrived just after a new snapshot stopped waiting for it, because it was answered from the snapshot the API already held. A caller who asks only about once a minute still waited: by then two new snapshots had been published, the API held neither, and it had to read both before it could answer. On the production machine that took about 0.6 to 0.7 seconds, when a request answered from memory takes about 30 milliseconds.

Now the API reads each new snapshot in the background as soon as it is published (it looks every 2 seconds), so by the time a request arrives the snapshots are already in memory. In our measurements on a laptop with production data, a request that came after two new snapshots dropped from about 170 milliseconds to about 3, which is the time of any request answered from memory. On the production machine it should drop from about 0.6 seconds to about 30 milliseconds. This applies to GET /v1/matching-markets/sports, and to a lookup for settled events (include_settled=true), which reads the snapshots the same way. A lookup by event id or source_id already found a game in the newest snapshot straight away.

The same goes for games that have just finished. The API also keeps a copy of today's finished games in memory, and it refreshed that copy only when a request found it 30 seconds old, so a caller who asks about once a minute could be answered from a copy that was a whole request behind, and miss a game that had only just left the live data. Now the API refreshes that copy every 30 seconds whether or not anyone is asking, so it is at most about 30 seconds old for every caller, not only for callers who ask often.

One thing is slightly different. For up to about two seconds after a new snapshot is published, until the API has read it, a response is built from the snapshot before it, so a game that matching only just added can be missing from that response. The next request has it. snapshot.observed_at still dates exactly the data the response was built from.

No field, parameter or status code changed, so nothing in the SDKs needs updating.