title: Which HTTP response code to use when the request takes too long?
body: <p>I'm building an API that does analytics on a very large database we are storing.  Some requests take a very long time to process. We want to proactively abort requests that take more than 10 minutes, but we don't know if a request will take that long until we try it. Most of the time, it's not because of transient server overloading. It's that the user made a request involving so much data that we simply can't get through it fast enough.</p>
  <p>I've scoured the <a href="https://www.rfc-editor.org/rfc/rfc7231" rel="nofollow noreferrer">list of standard HTTP response codes</a> but I can't find one that clearly fits:</p>
  <ul>
  <li><p><code>409 Conflict</code> - Maybe? The user could change their request to involve a smaller data set. But we feel like it's more of a server issue, not a client one.</p>
  </li>
  <li><p><code>422 Unprocessable Entity</code> - Maybe? We use this for other validation errors like bad date formats or dataset names. But it's not really a client error in this case.</p>
  </li>
  <li><p>Other <code>400</code>-level codes - It's not a bad request or an auth issue. We think we <em>should</em> service the request but we can't.</p>
  </li>
  <li><p><code>500 Internal Server Error</code> - Maybe this? But it feels too generic. This is what comes with bugs and unexpected issues.</p>
  </li>
  <li><p><code>501 Not Implemented</code> - Maybe? We kind of haven't implemented support for requests that involve an excessive amount of data. But the RFC seems to imply this is for when the request method isn't implemented. But the method is not the issue here.</p>
  </li>
  <li><p><code>503 Service Unavailable</code> - But the problem usually isn't temporary. Repeating the request would most likely fail with the same problem.</p>
  </li>
  <li><p><code>504 Gateway Timeout</code> - Technically this could be valid because we have a public-facing API service which proxies these requests to an internal service.  But we don't necessarily want to expose this implementation detail to customers.</p>
  </li>
  </ul>
  <p>Which is most appropriate / least bad? Or is there another I should consider?</p>