Hello Dgraph community!
I’m working an application involving voting, and I need to limit the number of votes a user can cast (to lets say 100). User’s can freely cast and remove votes to other nodes, subject to the constraints that the total number of votes must be between 0 and 100. I’m currently using facets to record the number of votes from one user to another, so a vote between users is represented by a vote edge with a number facet.
My question is concerning the best practices for keeping track of the number of votes cast by a given user. As I see it there are two ways to do it:
- Recalculate the number of votes cast whenever a user tries to add or remove a vote.
- Keep a running sum of the number of votes cast, and use that to decide if the user can add or remove a vote.
I’m currently using the second option, but I don’t like the idea of not having a single source of truth to consult, and the greater potential for errors bother me. However the first option seems computationally expensive and not particularly scalable - though if there can be at most 100 edges to sum the facets over, maybe my worries are misguided.
Any feedback or suggestions (is there a third option I haven’t thought of?) would be appreciated!