Long running process in NodeJS

More often than not, we don’t come across the situation where, in the context of Javascript based web application, a client request needs to run really long before its able to send response back to the client. While there can be many ways to handle such situation, such as queues, one solution can be, off-loading the processing of long running request to another thread. This method, of course, has its own set of pros and cons.

Pros:

  • Does not involves external components such a queue
  • NodeJS supports IPC when using the module child_process
  • Child process executes independent of parent process
  • Parent process can pass argument to the invoking of child process, which are received as CLI arguments.

Cons:

  • If the child process fails / crashes, there is no simple way to put retry.
  • Since the child process runs separately, it will consume some memory of its own because of independent execution context.
  • If required, a polling mechanism has to be built to know the status of child process.

I have created a simple example of the aforementioned concept. Please find it here. The README.md describes how the solution works.

To view or add a comment, sign in

More articles by Vishal Raj

  • AWS - Amazon File Cache

    Introduction Very recently AWS introduced a new service called Amazon File Cache. So what is this? Amazon File Cache is…

  • Quick intro to AWS Devops Guru

    Introduction to Devops Guru During the AWS re:Invent December 2020 event, AWS announced the release of a…

  • Getting started with React & TypeScript

    This post is inteded for developers looking to get started with frontend development using the following React…

  • Using AWS to host a static website

    This might be just one of the articles in already existing plethora of similar articles, teaching how to host a static…

Insights from the community

Others also viewed

Explore topics