The Recovery operation ensures that the state of the SDK (and therefore the system using the SDK) is in-sync with the state of the feed
When the feed is opened, Producers start in Down state and the recovery is automatically initiated to get the current state.
Each recovery is associated with and tracked per single Producer.
Since SDK does not persist any information between runs, a user must provide a producerRecoveryFromTimestamp from which the recovery will be made. Once the user processes all the recovery messages, the SDK is in-sync with the state of the feed, the Producer is marked as Up. The recovery timestamp can be determined by calling an appropriate method on the producer object lastProcessedMessageGenTimestamp. This value should be periodically retrieved and stored to ensure it is available and up-to-date in case a restart of the system is required.
If producerRecoveryFromTimestamp is not set - full odds feed message recovery is going to be performed. The general rule is - the shorter the time frame, the sooner the recovery operation will finish. The customer is expected to make an effort to keep this time-frame as short as possible given their circumstances, as long-recoveries creates additional pressure on other producers and increase a probability of other Producers issuing additional recoveries, increasing overall Producer Down-time, which puts downwards pressure on the revenue the bookmaker is able to capture.
Each producer defines a maximum time frame allowed to be requested a recovery for, which can be consulted in statefulRecoveryWindowMinutes. Actual timestamp requested for each recovery initiated can be inspected via a onRecoveryInitiated callback consulting timestampRecoveryWasInitiatedFrom on a supply object.
Producer Status Change Events
Each time the state of the producer changes, the user is notified via global event / callback. The current state of the producer can be consulted in producerStatusChange callback's isDown method. The following are the possible values and their corresponding meanings:
Alternative ways to inspect Producer Up or Down state are by consulting relevant methods on ProducerManager or by Producer.
producerStatusChange callback's producerStatusReason method rovides additional context for Producer changing its state. The following are the categories ProducerStatusReason are classified into:
FirstRecoveryCompleted - this ProducerStatusReason indicates Producer has just been marked Up right after its initial recovery and this reason is going to appear only once per Producer in the lifetime of the SDK run.
Feed messages are time critical for the bookmaker to make important betting market related descisions in a timely fashion. A bookmaker operating stale data risks loosing on their revenues by providing bets to punters for the events for which outcomes are already known. SDK will bring the Producer Down or Up depending on the speed of processing of feed messages.
Even though slow processing of feed messages on the customer end results in Producer being marked as Down, the remote producer is actually healthy and continues producing messages.
It is possible to increase Producer Up time at the cost of operating no as up-to-date messages. The tolerance for the level of not-up-to-date messages can be configured by the configuration option inactivitySeconds. It has a sensible default value, which should be carefully considered before modifying to ensure a right balance between overall Producer Down time and the bookmaker tolerance to operating stale data is struck. After bringing the Producer Down due to slow processing of feed messages, SDK will continue delivering messages even after the Producer is marked Down expecting the speed of message processing to recover. In this case no recovery will be issued.
ProducerStatusReasons related to slow message processing are the following:
Consulting isDelayed on ProducerStatusChange callback is an alternative way to find out about slow message processing.
Accessing deeper insight about processing delay
Considerations
Slow processing of feed messages is usually caused by the customer's registered OddsFeedListener not keeping up with the speed of message delivery.
Customer is highly encouraged to consider implementing concurrent consumption of feed messages on their end.
Current implementation of the SDK delivers messages sequentially in each of the configured UofSessions, hence messages which take long time to process by any of the UofSessionMessageHandler methods - will delay the processing of subsequent messages, potentially bringing the Producer Down.
Delays usually are caused by:
To reduce the frequency of Producers being Down due to slow message processing it is highly recommended to return from the listener method as soon as possible, handling the bulk of potentially slow/blocking operations related to the message asynchronously.
Complexities associated with implementing concurrent implementation
The principal complexity associated with asynchronous handling of messages, when implementing concurrent implementation on the customer end, is preserving the feed delivery order of messages for any given event. The following is the example ilustrating the scenario:
Assuming there is sport event happening between Real Madrid vs Barcelona and there are 2 subsequent OddsChange messages delivered for the market 1x2 in the user-configured session within the SDK. The first message carries odds of 1.1 1.3 1.5 meanwhile the second carries odds 1.2 1.3 1.4. If these messages end up being processed by 2 different threads on the user end, and due to the race condition their the first message gets delayed and, as a result, is handles after the second one was handled - bookmaker will be publishing wrong odds, providing a punter with an advantage.
Solution - Adjust tolerance to slow delivery
Configuration option inactivitySeconds allows the customer to permit lower amount of Producer Down-time at the cost of increasing the risk of operating with stale market data.
The default configuration option provides a sensible default value and should be changed only after carefully considering consequences.
In some cases SDK will not be able to continue with stable message delivery. In these cases a Producer will be marked Down providing one of the subsequent ProducerStatusReasons:
After the issue is resolved - SDK will bring Producer back Up again along with the ProducerStatusReason:
When Producer is marked Down - the customer does not need to take any action for the SDK to recover. Several mechanisms are implemented within the SDK to handle automatic recoveries to eventually bring Producers back Up again.
Considerations
Full recovery
All feed messages since recovery timestamp (see "Recovery timestamp") is going to be recovered automatically, when SDK detects a need for doing it. The customer cannot initiate this process on demand.
Manual recovery of a single sport event
Recovery of the certain type of feed messages corresponding to a single sport event can be requested manually via EventRecoveryRequestIssuer providing two options:
The recovery targetting a single event might be useful to be considered if the customer is aware of not having processed messages on their end due to their system failure, which was eventually successfully recovered from.
Producer is accessible in each message delivered from the feed. Alternatively producers, their state and recovery related information could be accessed via ProducerManager.
The most effective and safe way to decrease recovery times is to consider reducing time frame recovery is requested for. See "Recovery Timestamp" section.
The length of recovery operations have a time limit - indicating the maximum time window in which they need to complete i.e. all the messages related to the recovery are processed and the producer is up-to-date. If the recovery is not completed in a specified time window, it is automatically restared by the SDK.
Certain set of configurations permitations of maxRecoveryTime, minIntervalBetweenRecoveries and recoveryTimestamp may cause a higher risk of SDK entering into an infinite loop of recoveries, which can cause API to start throttling recovery requests due to too many recoveries requested, which is likely going to bring SDK into the state where it cannot ever recover without manual intervention. SDK provides tested default values for these configuration options which are compatible with API throttling behaviour. Changing these values requires extreme care and extensive testing performed beforehand.
Considerations
Today SDK does not provides a way of detecting infinite loops of never-ending Producer Recoveries. SDK does not provide a way to auto-recover from such state if that actually happened. The suggested best-effort workaround to acquire information about the currently being issued recoveries are via SDKProducerStatusListener.onRecoveryInitiated callback, which can provide indirect insight into detection of this problem, but this workaround still requires a judgement call and manual intervention.