First time visiting, glad to be part of this community.
I’m developing an inventory service and I have the following entities:
Company Inventory ( can be multiple depending on region/country )
Basically, the products are containers (categorized by type: S/M/L).
Not having a unique identifier for each container.
As a result, inventory is saved at the quantity level.
For example : container type : S , quantity : 5000
Business inventory is managed by the company, so when it runs out, we will add more from the same type.
UserInventory on the other hand , is maintained for the period that the user rents the container ( no purchases in the app , only rentals )
So for example, if a user is now renting a container from a specific business,
we need to decrease the quantity from the rented types in the business inventory, and add those to the UserInventory.
The same applies for filling stock for the business .
The opposite is true when returning rented containers.
Each container within the same “order” can have a different return time.
Container can have different status at the UserInventory level ( active / charged )
[charged if the user is late for the rental period]
And different statuses on Business Inventory level ( active/ dirty … )
And different statuses on the Opa inventory.
My questions are:
1.Is it better to maintain a single document for user per container type ( so 3 types, 3 documents per user) and the same for business ? Each container type has one document that holds all the user rents, business holdings, and company holdings.
did the inventory documents need to be on the collection ( otherwise , how can I make sure that both add/subtract from both inventories are occurring)
In regards to question 1, I feel like there is a chance of losing data. This is because multiple users will try to update the same business inventory document. This is because decrease / increase the stock will override other operations.