In my PHP Laravel application, I want to display special offers to users, depending on the quality of their house(s).
There are 4 Models:
Usercan have many
Houserecord has details like
Offerrecords holds the details of the offer like
OfferTargetingdefines the requirements that a
Househas to have, in order to show the respective offer to the user.
Currently, I run a comparison each time a user visits the offers page, which takes a while since there are many targeting criteria that need to be considered. The problem is that it takes too long and uses too many resources.
What's the correct way to determine which user should see what offer? I already thought of a background job that runs the comparison hourly and stores the results in a new table, like:
But I have ~20k users with ~30k houses and each comparison would take at least ~1.5 seconds, so it would be too huge.
What's the correct approach to this? How do companies like Facebook realize their targeting mechanism?