1

I am using the following code to create a request from my node application to call an API.

var options = {
      host: "www.something.com",
      path: "/api/something.php",
      method: "POST"
    };

var request = https.request(options, callback);
request.write(str);
request.end();


Sometimes I am getting a response with Status Code - 504

Will increasing the timeout of the app help?

When I get a response with 504, does it mean the the gateways in between my client and the API server gave up?

Or is the problem with my client?

rahulroy9202
  • 2,730
  • 3
  • 32
  • 45

1 Answers1

1

Use circuit breaker.

The basic idea behind the circuit breaker is very simple. You wrap a protected function call in a circuit breaker object, which monitors for failures. Once the failures reach a certain threshold, the circuit breaker trips, and all further calls to the circuit breaker return with an error, without the protected call being made at all. Usually you'll also want some kind of monitor alert if the circuit breaker trips. https://martinfowler.com/bliki/CircuitBreaker.html

enter image description here

julianusti
  • 191
  • 1
  • 9