couper icon indicating copy to clipboard operation
couper copied to clipboard

Backend react to 429 status - Too Many Requests

Open malud opened this issue 1 year ago • 0 comments

Couper should react to 429 status-code responses and will retry this particular request with the given delay from the response header Retry-After (in seconds). Maybe there is just the status-code without Retry-After header then we fallback to a configurable (default)value. In an ideal world the related backend would block/hold all other outgoing requests after seeing the first 429 but this will have no priority for the first implementation and could be somehow bypassed while reducing the max_connections.

We have to consider to buffer the request.body for a possible retry. While seeing the backend.retries block(or attribute) at startup, we have the option to enable this particular BufferOption.

So to not break our existing behaviour this would be an opt-in option and will give us the knowledge that we have to buffer all client bodies for this particular route.

Real world examples:

  • https://learn.microsoft.com/en-us/graph/throttling#sample-response

possible configuration:

backend {
  retries = true #opt-in
  # or for refinement options
  retries { # opt-in
    fallback_retry_after = 20s # fallback for a missing `Retry-After` header value; default: 10s
    status_codes = [429, 503] # default 429
    attempts = 2 # default: 5; must be greater zero
  }
}

malud avatar Apr 06 '23 10:04 malud