I would like to implement something similar, but I'm running into some problems. I would like to know what my options are to approach this problem, and what are the common techniques used in this scenario. (See bottom of this question if you are unfamiliar with Netflix)
Current Approach Create a "controls" table that houses information about a customer's status and cross references it to a service plans table.
controls(member_id, movies_rented_this_month, movies_at_home)
plans(movies_per_month_limit, movies_at_home_limit)
When an item is returned check the controls table to see if the customer qualifies to receive another order.
if controls.movies_at_home < plan.movies_at_home_limit
and if controls.movies_this_month < plan.movies_this_month_limit
For anyone who has no previous order (new customer), or who has nothing in their movie queue at the time of closing an order, we create a scheduled event to create the orders (polling).
Problem We need to account for how many orders each customer can have based on their plan. The aforementioned logic fails in some scenarios:
plans.movies_this_month_limit = 4, controls.movies_this_month = 3
plans.movies_at_home_limit = 2 , controls.movies_at_home = 0
In the above scenario a customer who qualifies for one order will receive two. Reversing the criteria reverses the problem.
Simplified Schema
members(id, plan_id)
movies(id, title)
plans(id, movies_at_home_limit, movies_per_month_limit)
controls(member_id, movies_at_home, movies_this_month)
movie_queue(member_id, movies_id)
Netflix An online movie rental service that allows a member to keep a wishlist of movies. Customers receive movies incrementally from their wish list (by mail), based on their type of plan.