feat(routing): add support to handle gateway latency during SR routing#126
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for handling gateway latency during Success Rate (SR) routing by introducing transaction latency tracking and penalization logic. The implementation allows merchants to configure latency thresholds and automatically penalizes gateways that exceed these thresholds during scoring.
- Introduces
txnLatencyfield across multiple data structures to capture gateway response times - Implements latency threshold checking in SR routing algorithm to skip rewarding slow gateways
- Adds comprehensive Cypress test framework for validating routing flows and latency-based scoring
Reviewed Changes
Copilot reviewed 15 out of 17 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/types/txn_details/types.rs | Added txnLatency field to TxnDetail and defined TransactionLatency struct |
| src/types/routing_configuration.rs | Added txn_latency field to SuccessRateData with TransactionLatencyThreshold struct |
| src/feedback/types.rs | Updated UpdateScorePayload with txnLatency and made Milliseconds cloneable |
| src/feedback/gateway_scoring_service.rs | Implemented latency threshold checking and penalization logic in scoring |
| src/feedback/utils.rs | Modified to populate txnLatency from API payload |
| src/decider/gatewaydecider/validators.rs | Set txnLatency to None in parser function |
| src/decider/gatewaydecider/types.rs | Added txnLatency field to structs and defined threshold configuration |
| package.json | Added Cypress testing framework configuration |
| cypress/* | Complete test framework for routing flows validation |
PriyanshuC132
approved these changes
Jul 31, 2025
Sarthak1799
approved these changes
Jul 31, 2025
ShankarSinghC
approved these changes
Jul 31, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Merchants usually have a time limit for the order create call, if the gateway takes more time than a predefined value merchant will consider the request as stale and mark the transaction as
PENDING_VBV. To avoid this situation its better to ignore those processors which are having high order response time.As part of the existing SR routing algo we are adding support to handle this latency check by which we can pass the time taken by the gateway during the order create call. Our SR logic will skip rewarding the processor if it breaches the merchant configured threshold.
Tests
Response
Response
Response
Response
Response
Response
As expected score of "GatewayC": 0.995 is reduced
Response
Response
Score of gatewayA remains unchanged
pending_vbvto make sure temporary penalty is applied for gatewayACheck redis to see if the gateway is penalized
Check redis to see if the score is rewarded back
Response
check Redis
Check redis and logs to see if the score is unchanged
Score remains unchanged as we don't update the gateway score when txnLatency is above configured threshold
Response
Response
Run cypress tests with

npm run testThis pull request introduces changes to incorporate transaction latency (
txnLatency) as a new field in multiple structures and functions, enabling latency-based decision-making in routing and scoring logic. Key updates include adding thetxnLatencyfield, defining a newOrchestrationLatencyThresholdstruct, and implementing logic to penalize transactions exceeding latency thresholds.Enhancements to data structures:
src/decider/gatewaydecider/types.rs: AddedtxnLatencytoDomainDeciderRequestForApiCallV2andOrchestrationLatencyThresholdtoSrV3InputConfigto support latency-based routing. Defined theOrchestrationLatencyThresholdstruct to configure latency thresholds for gateways. [1] [2] [3]src/types/txn_details/types.rs: AddedtxnLatencyas an optional field inTxnDetailto capture transaction latency in milliseconds.src/feedback/types.rs: UpdatedUpdateScorePayloadto includetxnLatency, and madeMillisecondscloneable for reuse. [1] [2]Routing and scoring logic updates:
src/feedback/gateway_scoring_service.rs: IntroducedisLatencyAboveConfiguredThresholdto compare transaction latency against thresholds. ModifiedgetGatewayScoringTypeto penalize transactions exceeding latency thresholds by returningGatewayScoringType::PENALISE_SRV3. [1] [2] [3]Parsing and utility updates:
src/feedback/utils.rs: UpdatedgetTxnDetailFromApiPayloadto populate thetxnLatencyfield from the API payload.src/decider/gatewaydecider/validators.rs: SettxnLatencytoNoneinparseFromApiTxnDetailto handle cases where latency data is unavailable.Additional changes:
src/types/routing_configuration.rs: Addedorchestration_latency_thresholdtoSuccessRateDataand definedOrchestrationLatencyThresholdfor routing configurations. [1] [2]src/types/txn_details/types.rs: ImportedMillisecondsto enable usage inTxnDetail.