DEV Community

Vishal Raj
Vishal Raj

Posted on

1

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 list 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.

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

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay