After spending most of time working on codebase with event-loop based concurrency approach, I recently joined a project that uses a more conventional thread-based concurrency approach. And wow, this makes me realize how unnecessarily complicated thread-based concurrency approach is, especially for the use case of building web applications. In this article, I want to talk about how I feel the future direction should be.
For readers who are not familiar with the two common concurrency approaches, I suggest reading this wonderfully written Stack Overflow answer: https://stackoverflow.com/questions/34855352/how-in-general-does-node-js-handle-10-000-concurrent-requests.
While thread-based concurrency approach offers a more fine-grained control over the level of parallelism that can happen, it's just to complicated for general web-application use cases. Debugging where locks are incorrectly placed, and where potential race-conditions could happen is just too much work, especially considering any sizeable backend would eventually need to be horizontally scaled anyway. I also think the complexity costs to code and maintain thread-based concurrency code is too much when compared to the performance gain it could create for typical web applications.
Given the number of cores and raw performance that hardware provides are improving in a much faster way than developers learning to write parallel code, the need of frameworks that makes it easy write parallelize code is the direction to go. And I do think event-loop driven concurrency is the way to go. NodeJS, in my opinion, has done a great job on making event-loop driven programming enjoyable. Through NodeJS, a lot of junior developers without any background in how computer memory model works have been able to write parallel programs without even realizing that! :)
To summarize, I think event-loop driven concurrency has been one of the best inventions in the past decade in the realm of web development. I'm totally looking forward to see how event-loop driven approaches would evolve in the next phase. For example, I'm curious how would LibUV evolve next. As interesting fact, Deno, which is created by the author of NodeJS, seems to use Tokio in favor of LibUV. I am going to do more research on the reasons why.
Top comments (0)