504 - Gateway timeout

  • As the http message description says if the Gateway doesn’t receive the response after a stipulated time, the http-request is timed out and it responds the same to the caller.
  • If the the service is behind gateway it leads to 504-Gateway timeout
  • 504-Gateway Timeout
  • How to fix 504?
    • Improve API performance that responds within the max timeout limit of gateway.
      • Example: If the Gateway timeout is 20 Seconds, ensure your service responds within 20 seconds.
        • Note: The service may be still processing the request and after 20 seconds it might successfully complete, but the gateway disconnects from the server and informs the caller that the request is time out. It’s futile if the request is successfully processed by the service.

503 - Service Unavailable

  • When all the application-server worker threads are occupied and no new threads are available to serve anymore then the service rejects all the new incoming requests with 503-service unavailable.
  • How to fix 503?
    • Ensure that the app-server threads are released quickly and capable to handle the incoming load by scaling up horizontally with instances.
    • Use DeferredResult to free up application worker threads
    • Break down the complex request processing flow and assign the tasks to threads in thread pools.
      • Use @Async in spring boot having dedicated thread-pools for specific category of tasks say “db-inserts” pool having threads that will do all database inserts.