I have a web application that utilises two collections in a MongoDB database:

  • Ingredients
  • Recipes

An example of the problem

  1. A chef creates a new recipe, which is added to the Recipes collection.
    • The recipe is automatically classified as vegetarian, because it contains only vegetarian ingredients.
  2. A vegetarian user adds the chef's recipe to their favourites - an array of IDs referencing their favourite recipes.
  3. The chef updates their recipe to include meat.
  4. The vegetarian user unexpectedly sees a non-vegetarian recipe in their favourites.

I would like for the vegetarian user to:

  • See that a recipe in their favourites has been updated, but
  • Continue be able to view the recipe they favourited.

I hope this make sense.

Please can someone in the know help me understand a scalable way of tackling this problem? This system will eventually contain millions of recipes.

  • 1
    "Please can someone in the know help me understand a scalable way of tackling this problem?" Yes 1. Don't use a document store and 2. Build the data model so meat can't be added to recipes that are vegetarian/etc. or make sure the classification is verified before the change is allowed to be committed. 3. Maintain a version/history of each recipe. 4. Determine what business rules should be around notifying a customer if certain changes have been made to a recipe.
    – user212533
    Nov 17, 2022 at 15:15
  • Thanks, @bbaird. Vegetarian is one of many classifications. There are others e.g. high protein, which are based on nutrition values. Recipe's should be easily updated, but not 'break' things that depend on them. User favourites was a contrived example, sorry. We have menus (containing recipes) that also bear classifications. The 'notification'/flag should be present when reading the menu, i.e. a recipe has been updated and the change would break your menu classification.
    – Check12
    Nov 17, 2022 at 15:37
  • I second bbaird, this smells like it shouldn't be using MongoDB and should use a RDBMS instead.
    – J.D.
    Nov 17, 2022 at 19:49


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.