How to design a rewards system on my website

4.1k views Asked by At

I want to try and design a reward system on a new website I am building. For example (for illustrative purposes only):

enter image description here enter image description here enter image description here

Stack overflow's medals system is another example.

My question is, you can store the description and name of each badge easily in a database table.

**tbl_Badges**
ID  |  Badge Name  |  canHaveMultiple   |  hasProgress  |  progressScale
----------------------------------------------------------------------------
1     Copy Editor     Yes                    No                null
2     The Mob         Yes                    No                null
3     Jquery          No                     Yes               100

And then to associate users with these badges:

**tbl_UsersBadges**
ID  |  Badge ID  | User ID
---------------------------
1      1            5
2      1            5
3      2            5
4      2            12

(And perhaps another one to store user progress through scale badges etc etc)

But the difficulty comes in programming the triggers that award these badges.

Are systems like this built with hard coded triggers in the website? This is about the only way I can think of doing it due to the broadness and flexibility of these badges. However if the triggers are hard coded to a badge ID, you are going to have to be extremely careful when changing anything.

So is this how such a system works? It goes against what I have learnt. Or am I approaching the problem wrongly?

2

There are 2 answers

0
jonjbar On BEST ANSWER

First you need to make sure you have a clear list of "rewarded" user actions. Then, you have to create some code which will be triggered when one of those actions happen. There are multiple ways of looking at the solution:

  1. Save each action which might lead to a reward in the database. Then, either actual triggers in the database will grant badges based on those action properties, or a crontab job might do the work. Benefits are that if you change your reward system calculations, you can replay user actions to get back the new reward;
  2. Code some hub method which is automatically called before calling any other methods. Based on the action, you can grant awards then and redirect to the real method afterwards;
  3. Use hard-coded actions as you mentioned but this is tedious and error-prone;
0
Alessandro On

I would just throw events from the software and catch them, even asynchronously, from backend helpers which will add badges, schedule notifications and so on. You can use a messaging system (AMQP or similiar) to handle these events from backend helpers.