You could stream your response to the client. It will involve several stages in your stream pipeline.
Client opens the request, so you then:
- get the connection
- get the result stream, preferably something in object mode that gives you row by row
- pipe it to a stream that will convert result set row into a CSV table row (or excel, not sure if you can make that work as a stream though).
- pipe that stream to response.
Then your stream is nice and non-blocking. It's still CPU hungry and lasts long, but it doesn't block the server completely, so you can serve multiple clients in the same time.
Alternatively, spawn another process that will run your conversion (like json2xls). So your server takes a request, and if there is available capacity, spawns a process to handle this conversion, returning you a tmp file location or something of the sort. Then your server will still work for the other, regular requests because this processing is essentially off your main process.
Or do something like a two-step process - take the request and put it on your job queue - then tell the client "ok, I'll inform you when it's ready". Then this job queue is on a separate node or similar process, and it informs the client when the xls is ready ;)