Reputation: 196
I am building a web based chat application using Node.js. I am kinda building it gradually while the app is already running in a Node.js PaaS and being tested by my bunch of friends. The thing is, I can't spend much money on database services to store chat history.
So I am designing a sophisticated file-based database system just like SQLite. Although I am aware that SQLite does similar job, I wanted to store data in a JSON format. The reasons are many. One notable reason is, to reduce CPU usage, I will just send raw JSON data to clients where they will be rendered properly using AngualarJS.
My questions are:
Please note that this solution is only for trivial data storage like chat history. I am not gonna use this method for a large and serious web applications.
Update: I don't want to use MongoDB or others since I cannot afford them for this project. I want to store data in a flat-file and place it in a disk. Because, many PaaS providers give 1GB of disk space at just $1 whereas 1GB of MongoDB storage is very high... also they even bill us for the amount of data transferred, number of PUTs and GETs etc.
Upvotes: 2
Views: 3193
Reputation: 2935
What are your opinions on this method?
The method is a good method, however due to the lack of structure in an SQLite-like database you will run into issues if you handle large amounts of data. However, JSON with NodeJS work well together, so you have a strong reason for wanting to use these two.
Is this method both vertically and horizontally scaling?
In a simple implementation of this, it is vertically scaling but not horizontally scaling. It is easy to add more drives to a server, but much harder to implement a scaled, distributed, fault-tolerant software, and the list goes on... There are many reasons why horizontal scaling is much harder with software, and the bulk that comes with MongoDB and alike systems are meant to solve the horizontal scaling issue. If you want less bulk, you don't get horizontal scaling (typically), and if you want horizontal scaling, you get more bulk.
What are the possible security issues?
You need to watch out for JSON-injection. Here are some resources about JSON injection: http://www.slideshare.net/null0x00/json-injection https://www.owasp.org/index.php/OWASP_AJAX_Security_Guidelines#Protect_against_JSON.2FJavaScript_Hijacking
Is there any alternative method available?
As other questions suggest, going for a pre-created database software like MongoDB, MySQL, and RethinkDB would be your alternative method. Please remember, though, it is free to host these your own.
Notes + Sources
Might want to take a look at https://github.com/boboman13/flatfile.
Sourced from my own experience with this.
Upvotes: 2
Reputation: 177
I know MongoDB (and possibly others) is using binary JSON format. I would look into that to make sure you are not reinventing the wheel. At the very least I would say that since there is a Node.js-library for MongoDB, it might be a good trade-off between having the sort of efficiency you require and ease of implementation (since you won't need to write the database software, hence allowing you to focus more on the application itself).
Upvotes: 0