💡 If you like this website, please share it with your friends and network! 🚀
Back to All Questions
Question 93 of 100
Error Handling & Debugging
Advanced

Q93: What Happens If an API Request Takes Too Long to Respond?

⏱️Core Concept

What Happens If an API Request Takes Too Long to Respond?

Key Takeaways & Architecture Summary

  • Triggers client-side timeouts, terminating the connection.
  • Starves backend server thread pools, slowing down other users.
  • Causes intermediate gateways or proxies to return an HTTP 504 Gateway Timeout.

Direct Answer Summary

When a request takes too long to respond, it triggers connection timeouts. The client-side connection is terminated, and intermediate load balancers or proxies (like Nginx, Cloudflare) abort the connection, returning an HTTP 504 Gateway Timeout to the client.

⚠️ Senior Engineering Warning (Red Flag)

Never allow API requests to run without explicit connection limits. If a backend database query hangs, the server thread remains blocked, which can quickly exhaust resources and crash the service.

💡 STAR Architectural Explanation & Pro Tip

Timeout limits prevent cascading failures in microservices. If service A fails to respond quickly, downstream services should terminate the connection to protect the cluster.

RestAssuredTest.java
Rest-Assured + Java
// Postman timeout assertion check
pm.test("Verify endpoint latency satisfies performance SLAs", function () {
    pm.expect(pm.response.responseTime).to.be.below(5000); // 5 second timeout limit
});