views:

72

answers:

1

I'm coding a new {monthly|yearly} paid site with the now typical "referral" system: when a new user signs up, they can specify the {username|referral code} of other user (this can be detected automatically if they came through a special URL), which will cause the referrer to earn a percentage of anything the new user pays.

Before reinventing the wheel, I'd like to know if any of you have experience with storing this kind of data in a relational DB. Currently I'm using MySQL, but I believe any good solution should be easily adapted to any RDBMS, right?

I'm looking to support the following features:

  • Online billing system - once each invoice is paid, earnings for referrals are calculated and they will be able to cash-out. This includes, of course, having the possibility of browsing invoices / payments online.

  • Paid options vary - they are different in nature and in costs (which will vary sometime), so commissions should be calculated based on each final invoice.

  • Keeping track of referrals (relationship between users, date in which it was referred, and any other useful information - any ideas?)

  • A simple way to access historical referring data (how much have been paid) or accrued commissions.

  • In the future, I might offer to exchange accrued cash for subscription renewal (covering the whole of the new subscription or just a part of it, having to pay the difference if needed)

  • Multiple levels - I'm thinking of paying something around 10% of direct referred earnings + 2% the next level, but this may change in the future (add more levels, change percentages), so I should be able to store historical data.

Note that I'm not planning to use this in any other project, so I'm not worried about it being "plug and play".

Have you done any work with similar requirements? If so, how did you handle all this stuff? Would you recommend any particular DB schema? Why?

Is there anything I'm missing that would help making this a more flexible implementation?

+1  A: 

Rather marvellously, there's a library of database schemas. Although I can't see something specific to referrals, there may be something related. At least (hopefully) you should be able to get some ideas.

Brian Agnew