https://tella.video/cluster-locking-challenge-1-1f05

<aside> 💡 This challenge was solved by one of our engineers internally.

  1. It took 1 hour 15 minutes approximately.
  2. Our challenge.mjs file is 96 lines long.

</aside>

What To Build

  1. Imagine you have a service that does some expensive operation.
  2. This expensive operation only needs to be done once for each piece of data.
  3. To improve performance, instead of one server you’re using two servers running the same code balancing among themselves.
  4. Ensure that even if multiple requests for the same data comes in, into two different servers, the actual work is only done once.

Details

  1. Modify only challenge.mjs do not modify any other file.
  2. Do not use any external libraries to solve the challenge.
  3. You can use send(string) to send data to the other server instantly.
  4. You should be using test.mjs to send hundreds of requests to both servers at the same time to see if your servers sucessfully only handle each task only once.
  5. In the onRequest function inside challenge.mjs you will have to call await doWork() and console.log the returned data.
  6. As the request will be handled only once, your code should console.log only once.

Let’s Start

Clone the repo first

git clone [email protected]:fringecore/fringecore-backend-challenge-cluster-locking.git

cd into the directory, and install npm packages.

cd fringecore-backend-challenge-cluster-locking
npm install

Open your favorite code editor (like vscode for example.)