DEV Community

Cover image for I made a big mistake.
Neel-Vekariya
Neel-Vekariya

Posted on

I made a big mistake.

I made a big mistake.

I stored the customer's address in every order document.

Then I needed to build a feature where customers could change their address.

I think this could be an easy feature. But when I planned to build it, I realized I had made a big mistake. To update the address, I needed to change it in all the order documents created by the customer.

I stored the address in every document because it made reading related information easier. But it cost me back because changing the address in all documents became an expensive operation for me.

Then I read about this problem and found that it was not only me, but other developers also had the same problem.

So, I looked for their solutions and found that one simple solution was to update the address only in those documents where the order had not yet been delivered.

Another option was to make the address field separate in the user_profile document.

But storing the address separately in the user profile also becomes somewhat expensive because when you need the order details, you need to extract the address from the user profile, which costs one extra operation.

I think, for me, updating only those orders that have not yet been delivered is the best option.

What are your thoughts on this design?

Top comments (0)