I have a very simple express app which stores information it receives from clients into a database without hardly any processing. Some simplified code to illustrate this:
app.post(ANALYTICS_ENDPOINT, async (req, res) => {
try {
await insertToDB(req.body)
res.status(204).send();
} catch (err) {
logger.error(err);
res.status(500).send();
}
});
This application is deployed to google cloud run and handles a high volume of requests per second. What we have noticed is that removing the await
keyword from the route allows each container to handle more requests, at the downside of not capturing errors - so clients will always receive a 204
.
The other use of await in this would be in insertToDB
function which again simplified looks like this:
const insertToDB = async (row) => {
await dbClient.insert(row);
}
As you can see here we are also using await
since this action returns a Promise.
So the question is, should we be awaiting when the caller does not expect a response? And can it be the case that avoiding these awaits we can handle more throughput on our app?
EDIT:
There is a similar question here. Yet I think this is different as I am mostly interested in understanding why removing the await
allows me to handle 2/3x the number of requests per second.