All status codes

5xx Server errors

504 Gateway Timeout

A proxy, load balancer or CDN waited too long for the server behind it.

Common causes

  • A slow database query or external API call.
  • The app is overloaded and responds too slowly.
  • A timeout in the proxy shorter than the work takes.

How to fix it

  • Find the slow part: database queries, external calls, heavy pages.
  • Move long jobs to a background queue.
  • Raise the proxy's timeout only if the slowness is expected.
Full troubleshooting guide502 vs 503 vs 504: what each error means and how to fix itThree gateway errors, three different problems: a crashed app, no capacity, or a slow backend. How to tell them apart, where to look first, and what Cloudflare's 52x codes mean.

Find out the moment your site returns 504

Spot Downtime monitors count this as down and alert you, since visitors see an error. (The public “Is it down?” checker treats 4xx answers from big sites as online, because many refuse automated requests.)