Should every controller action be async? I have heard it makes the API faster, but I also see people saying it does not help.
Should every controller action be async? I have heard it makes the API faster, but I also see people saying it does not help.
Async helps when your code waits on something outside the CPU: a database query, an HTTP call, a file read. While it waits, the thread goes back to the pool and can serve another request. That lets a server handle more concurrent requests with the same number of threads. It does not make a single request finish sooner.
Use it for I/O. Do not wrap CPU-heavy work in Task.Run on the server, because you just move the work to another thread.
Common mistakes:
In a modern ASP.NET Core API, making database and HTTP actions async is the normal default.