A program sends data to API using N concurrent workers as goroutines that consume data from a channel (Producer/Consumer pattern). API signals it can't handle more using HTTP status codes and demands a back-off.
Any links/pointers to this presumably already solved problem are much appreciated!
You can use select to control calling API
for _, k := range data {
select {
case <- backoff:
time.Sleep(backoffDuration)
default:
// Call API
// Check http status code and trigger backoff channel
backoff <- 1
}
}
Here is set-up:
Once these two are set-up you can control API calls by manipulating backoff channel and backoffDuration to control for how long routine will pause working.
Disclaimer: This is just pseudo-code.
You can check Hashicorp's library here. Looks like it will solve your problem