How I solved my first server crash @ lab.sokratik.com
Our first beta product http://lab.sokratik.com uses two nodejs servers, one of them is a binaryjs socket which is a wrapper around amazon s3, the other powers all the html you see on your browser. This is an expressjs application sitting behind nginx and talking to browser and mongolab.
Essentially the flow of data in our architecture looks like this
- Browser talks to expressjs server
- server gets data from mongolab via mongodb
- browser manipulates the json and sends it to expressjs
- expressjs sends it back to mongoose.
Since, my application has a few nested json documents. communication from browser to webserver to db server involves a lot of JSON.parse and JSON.stringify.
A typical document for our application looks like
The pain-point for me was property3. Since,in our application lots of asynchronous manipulation in the browser. A lot of times(very rarely) garbage data(null) creeps in.So we might have a object like
The omit(‘__v’) is kind of compulsory for mongoosejs and expressjs, I learnt it the hard way and will write about it later.