NoSQL database structure for chat application (using FireBase)

Since years of using relational databases, I have been trying to develop a fairly simple chat / messaging application using FireBase

FireBase uses the NoSQL data structure approach using formatted JSON strings.

I did a lot of research to understand how to structure a database based on performance. I tried to “denormalize” the structure and got the following:

{ "chats" : { "1" : { "10" : { "conversationId" : "x123332" }, "17": { "conversationId" : "x124442" } } }, "conversations" : { "x123332" : { "message1" : { "time" : 12344556, "text" : "hello, how are you?", "userId" : 10 }, "message2" : { "time" : 12344560, "text" : "Good", "userId" : 1 } } } } 

The numbers 1, 10, 17 are examples of user identifiers.

My question is, can this be better structured? The goal is to scale up as application users grow and still get the best performance.

+5
source share
1 answer

One case for storing messages might look something like this:

 "userMessages": { "simplelogin:1": { "simplelogin:2": { "messageId1": { "uid": "simplelogin:1", "body": "Hello!", "timestamp": Firebase.ServerValue.TIMESTAMP }, "messageId2": { "uid": "simplelogin:2", "body": "Hey!", "timestamp": Firebase.ServerValue.TIMESTAMP } } } } 

Here is an example from which this function flowed. This tutorial creates an application like slack using firebase: https://thinkster.io/angularfire-slack-tutorial

If you need something more specific, additional information will be helpful.

+2
source

Source: https://habr.com/ru/post/1244963/


All Articles