I\'ve got 2 firebase questions here :
A/ Is it a good practice to programmatically copy the ID to the local model (excluded from the database), when pa
Both solutions guarantee data consistency, but solution A is better than solution B when it comes to database size.
By using solution B, your database structure would look like this:
"posts":{
"nTY5U5NJJbPTJaPksPRNqau15H53" : {
"message" : "Hello World",
"sender" : "Rosário Pereira Fernandes",
"key" : "nTY5U5NJJbPTJaPksPRNqau15H53"
}
}
This should use around 180 bytes of disk space. Notice that this key is repeated twice on your node. Why not remove it to save space?
Using solution B, you'd have a smaller database:
"posts":{
"nTY5U5NJJbPTJaPksPRNqau15H53" : {
"message" : "Hello World",
"sender" : "Rosário Pereira Fernandes"
}
}
This would use around 135 bytes. That's 45 bytes less than solution B. Now imagine if you had 1000 posts on your database. You'd be using 45000 bytes more on solution B. This is enough space to store around 300 more posts, but it is being taken by the extra key attribute.
Don't forget that the Firebase Database has some price limitations for GB stored and GB downloaded. By using solution B you would reach this limit faster than by using solution A.