Normalization or denormalization structure(Notification to multiple recipients - business logic)

Hello all.

I can't decide whether to "normalize" the data or not.

I have notification datas in my app. When notification can be triggered for whole complay, user, or user in company.

My current data looks like:

Its one notification for users in company:

{
"id" : 1,
"subject" : "Some subject",
"content" : "Some content random size",
"recipient": "company_123123usr_111111",
"isUnread": true,
"notification": 1, 
"notificationCategory": 5,
}

{
"id" : 2,
"subject" : "Some subject",
"content" : "Some content random size",
"recipient": "company_123123usr_222222",
"isUnread": true,
"notification": 1, 
"notificationCategory": 5,
}

{
"id" : 3,
"subject" : "Some subject",
"content" : "Some content random size",
"recipient": "company_123123usr_333333",
"isUnread": true,
"notification": 1, 
"notificationCategory": 5,
}

.....

There are also notifications to just users or just companies, when notification have recipients - usr_333333 or company_12312 in company case.

This is the crux of the problem. Notifications created for company employees create too many notifications for each of the company's employees, i.e. There can be many options for recipients within a company:
"company_123123usr_111111",
"company_123123usr_222222",
"company_123123usr_333333"
etc.

My usually search looks like this

GET notify/_search
{
  "query": {
    "terms": {
      "recipient": [
        "company_123123usr_222222",
        "company_12312",
        "usr_222222"
      ]
    }
    ...
  }
}

I want notification recipients in one document as follows:

{
"id" : 1,
"subject" : "Some subject",
"content" : "Some content random size",
"recipients": [
"company_123123usr_111111",
"company_123123usr_222222",
"company_123123usr_333333"
],
"readRecipients": {
	"company_123123usr_111111": "company_123123usr_111111",
	"company_123123usr_222222": "company_123123usr_222222",
},
"unreadRecipients": {
	"company_123123usr_333333": "company_123123usr_333333"
}
"notification": 1, 
"notificationCategory": 5,
}

I want to search by fields recipients, readRecipients, unreadRecipients. In the readRecipients and unreadRecipients fields, I made an object instead of a list in order to effectively delete and add data by key when reading a notification.

There can be about 10 million unique recipients in the index. Do you think there is a problem with such “normalization” that I should pay attention to? I saw in the topic Accessing the value of a dynamic key in an object that having many dynamic keys in an object is bad. Maybe I should store everything as a list and every time I read (change is unread state) go through the entire array, but not create a dynamic object?

Thank you very much

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.