The structure detailed in the blog post does not store duplicate comments. We store comments once under /comments
then store the name
of those comments under /links
and /users
. These function as pointers to the actual comment data.
Consider the example structure from the post...
{
users: {
user1: {
name: "Alice",
comments: {
comment1: true
}
},
},
comments: {
comment1: {
body: "This is awesome!",
author: "user1"
}
}
}
Note that the actual comment data is only stored once.
If we modify /comments/comment1
, we don't need to update anything else because we only store the name
of the comment under /links
and /users
, not the actual comment contents.
If we were to remove /comments/comment1
, that would remove the only existence of the comment data. However, we still have these "dangling" references to comment1
under /users/user1/comments
.
Imagine we delete /comments/comment1
, when we try to load Alice's comments, we can look and see that comment1
doesn't exist anymore. Then our application can react accordingly by either a) deleting the reference or b) ignoring the reference and not trying to display the deleted comment.