3 minute read

IoT, Node.js, MongoDB, and a More Secure Residential Community

Jun 16, 2018 / Javascript

Last Updated: Friday, October 12th, 2018

Introduction:

SafeGate is a solution for guest access management inside gated residential communities. I am currently tasked to create the API and database design for the application, taking into consideration that this API would not only serve a front-end web UI, but eventually serve endpoints to an iOS client and a sensor placed in automobiles (internet of things, or IoT).

Tech Stack:

Arguments for the Chosen Tech Stack:

My first decision was to choose Node.js as the application backend. I am becoming more and more interested in the non-blocking advantages of using Nodejs as an application runtime. The decision to use Node was made based off of the fact that this application is going to be very data intensive. I will have a web client, an iOS client, and an IoT integration all making requests to the web server and will need to query the database for almost every single one of those requests. The problem with more traditional runtimes like Ruby or Java is that each request made to the API would be served by spinning up a computing thread to specifically handle the incoming request. So you would start up your server when launching your site and spin up a predetermined amount of threads to handle requests from a presently unknown number of clients. If you need more threads, you would set up your application to serve more threads than it started with. However, each one of these threads is costly in terms of physical computing hardware. As your business grows, and your userbase becomes more daunting in size, you run out of threads to serve. So you add another physical server. And another server.

These kinds of backend languages may not be the best for handling a large number of incoming requests, however they are great for heavy, intensive computing tasks. You wouldn’t want a Node.js application to handle a vector image editing program, or calculate extremely large scientific computations. Each language has its own advantages, and I plan to maximize the benefits of using Nodejs with this SafeGate application.

I am using Express because it builds on Node’s built-in web server. It tries to stay as native to Node as possible, however, I think it handles HTTP requests much more gracefully than Node and protects against serving error-decorated responses such as forgetting to send a res.end() function after a few res.write() functions.

I am using MongoDB over something like MSSQL or MySQL due to the flexibility you obtain when using it. No rigid schema. If three months down the line you need a certain table to have an extra field, and this and that, you just change it and it fits in nicely from there on out. This works perfectly for something like SafeGate, as I am expecting to run into heavy database modification when it comes time to integrate user management functionality into the application.

While I eventually plan to refactor my entire client-side part of the application to use Facebook’s React, I am building the MVP with a simple EJS view engine.