I have this code (non-essential information that it runs on EC2 instances in AWS, processing messages in the SQS queue).
The first statement in the method receives some data via http, the second statement saves the state in the local dynamo data warehouse.
public bool HandleMessage(OrderAcceptedMessage message)
{
var order = _orderHttpClient.GetById(message.OrderId);
_localDynamoRepo.SaveAcceptedOrder(message, order);
return true;
}
Performance characteristics are that a round trip is 100-200 milliseconds, and a dynamo record is about 10 milliseconds.
Both of these operations have versions async. We could write it as follows:
public async Task<bool> HandleMessage(OrderAcceptedMessage message)
{
var order = await _orderHttpClient.GetByIdAsync(message.OrderId);
await _localDynamoRepo.SaveAcceptedOrderAsync(message, order);
return true;
}
So the guide is that since the first operation "may take more than 50 milliseconds to complete," it should use async and wait. (1)
, ? :
: 50 .
async: . , , .
1) http://blog.stephencleary.com/2013/04/ui-guidelines-for-async.html