What is the difference between Node.js async model and async/await in .NET?

Technology CommunityCategory: .NET CoreWhat is the difference between Node.js async model and async/await in .NET?
VietMX Staff asked 3 years ago

The async model that has Node.js is similar to the old async model in C# and .Net called Event-based Asynchronous Pattern (EAP). The C#’s async/await keywords make asynchronous code linear and let you avoid “Callback Hell” much better then in any of other programming languages.

Node.js is asynchronously single-threaded, while ASP.NET is asynchronously multi-threaded. This means the Node.js code can make some simplifying assumptions because all your code always runs on the same exact thread. So when your ASP.NET code awaits, it could possibly resume on a different thread, and it’s up to you to avoid things like thread-local state.

The same difference is also a strength for ASP.NET, because it means async ASP.NET can scale out-of-the-box up to the full capabilities of your sever. If you consider, say, an 8-core machine, then ASP.NET can process (the synchronous portions of) 8 requests simultaneously. If you put Node.js on a souped-up server, then it’s common to actually run 8 separate instances of Node.js and add something like nginx or a simple custom load balancer that handles routing requests for that server.