Request Hedging

Tail Latencies

The Notifications’ Service

The Problem Statment

Request Hedging

The Solution

The Implementation

func (bq BaseQueue) enqueueWithSoftTimeout(msg string, timeoutInMs int, q Queue) (string, error) {

// the channel holding the result
c := make(chan struct {
id string
err error
}, 1)

// an async goroutine to enqueue the message
go func() {
id, err := q.Enqueue(msg)
c <- struct {
id string
err error
}{id: id, err: err}
}()

timeout := time.Duration(timeoutInMs) * time.Millisecond

// wait till timeout for the result to appear in the result channel
// else return
select {
case result := <-c:
return result.id, result.err
case <-time.After(timeout):
return "", fmt.Errorf("enqueue timed out after %d ms", timeoutInMs)
}
}

Why not use http transport timeouts?

--

--

--

A curious engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhishek Varshney

Abhishek Varshney

A curious engineer

More from Medium

Kubernetes scaler for dedicated stateful servers

ACT Access Controll Tree

In search of a Search Engine, beyond Elasticsearch: Introducing Zinc

How I implemented an ART (Adaptive Radix Trie) data structure in Go to increase the performance of…