Sobes.tech
Senior

Is it possible to immediately reject a request if a fast service has already returned reject, without waiting for a slow ML anti-fraud service?

sobes.tech AI

Answer from AI

Yes, it is possible to immediately reject the request if the quick anti-fraud service returns a rejection, without waiting for the slow ML service to finish.

This is a common approach to optimize response time and resource usage:

  • The quick service performs an initial check and immediately returns reject if there is an explicit rejection.
  • The slow ML service can continue processing asynchronously for logging, training, or subsequent analysis.

In Go, this can be implemented using channels and contexts, canceling the wait for the slow service's result upon receiving a rejection from the quick service.

Example:

fastResult := make(chan bool)
slowResult := make(chan bool)

// Run the quick service
go func() {
    fastResult <- fastAntiFraudCheck()
}()

// Run the slow ML service
go func() {
    slowResult <- slowMLCheck()
}()

select {
case fastOk := <-fastResult:
    if !fastOk {
        // reject immediately
        return reject()
    }
    // wait for slowResult or continue
case slowOk := <-slowResult:
    if !slowOk {
        return reject()
    }
}

This way, the system's responsiveness can be increased by not waiting for long checks if there is already a reason to reject.

Is it possible to immediately reject a request if a… - sobes.tech