Node.js server crashes , Database operations halfway?

Posted by Ranadeep on Server Fault See other posts from Server Fault or by Ranadeep
Published on 2013-10-20T08:44:36Z Indexed on 2013/10/20 9:56 UTC
Read the original article Hit count: 364

I have a node.js app with mongodb backend going to production in a week and i have few doubts on how to handle app crashes and restart .

Say i have a simple route /followUser in which i have 2 database operations

/followUser
----->Update User1 Document.followers = User2
----->Update User2 Document.followers = User1
----->Some other mongodb(via mongoose)operation

What happens if there is a server crash(due to power failure or maybe the remote mongodb server is down ) like this scenario :

----->Update User1 Document.followers = User2
 SERVER CRASHED , FOREVER RESTARTS NODE

What happens to these operations below ? The system is now in inconsistent state and i may have error everytime i ask for User2 followers

----->Update User2 Document.followers = User1
----->Some other mongodb(via mongoose)operation

Also please recommend good logging and restart/monitor modules for apps running in linux

© Server Fault or respective owner

Related posts about mongodb

Related posts about node.js