Sunday, January 10, 2021

Error with No Exception Thrown When Transferring Data from Amazon Elasticsearch Service to Amazon DocumentDB

We all wish our application performs as fast as possible and to do that sometimes we need to slow down.

Problem

I have a project in which I have to get data from Amazon Elasticsearch, process the data and save the result into Amazon DocumentDB. I processed the data asynchronously so my processing application performed really fast. Since the result accuracy is important, I deleted the result and rerun the process just to make sure the same input will produce the same result. However, the results are different and no error nor any exception is thrown.

Solution

After few hours of troubleshooting, I noticed that the data were not immediately available right after inserting them into DocumentDB. Since DocumentDB separate storage and compute, it took a bit of time to store the data and make them available. 

In my code, I need to immediately queried the inserted data. That means, sometimes, it saved the data fast enough that the data are available and sometimes they are not.

So my solution is putting a slight delay between insert and query code and I managed to get consistent result.


Running Express JS Application via Plesk in Mocha Host Windows Hosting

Nowadays, to run an application balancing best practices and ease of use need tons number of different technology. That means documentations are scattered too.

Problem

I have an Express JS application that I need to be hosted and since I have active plan under Mocha Host, I decided to host it there. My hosting server is Windows and it supports Node.JS. Looking into the settings, it is as simple as enabling Node.JS. However, after managing to deploy the application, it doesn't run as expected as it returns 404 for known url.

Solution

When I finally managed to solve the running issue, there are many steps that I need to configure to get my application working.

Step 1

I'm using Express JS version 4 generated via express-generator, so the starting script is not app.js, but /bin/www. So following the instruction in the article below:

https://www.plesk.com/blog/product-technology/node-js-plesk-onyx/

I created a new entry file called service.js. The content is simple as follow:

const app = require('./app');
const http = require('http');

http.createServer(app).listen(process.env.PORT);

Step 2

In Plesk under Websites & Domains > YOUR_WEBSITE > Node.js > Application StartUp File, change it from app.js to server.js.













Step 3

Ensure that Document Root and Application Root are the same. Unlike other hosting in which Document Root path = Application Root path + /public.

Step 4

Add the following into the web.config under <system.webserver> tag, so the Express routing works. 

<rewrite>
  <rules>
    <rule name="myapp">
      <match url="/*" />
      <action type="Rewrite" url="server.js" />
    </rule>
  </rules>
</rewrite>

The above is enough in my case. I don't have to add <handlers> and/or other suggested tags.

Step 5 (Optional)

In my case, I have to click the NPM install button in step 2 to install dependencies.

Also, you might need to restart the dedicated application pool or disable/enable Node.js. In my case, I didn't have to do that.

Other links that helped me figured this thing out: