Tuesday, November 24, 2026SubscribeMastheadAbout
Cali ReporterCalifornia · National · West Coast · Good News

Advertisement

Technology

Handling Points in a Rewards System: Ensuring Accuracy and Avoiding Double Payments

A rewards program built into a learning platform must ensure that points are awarded, redeemed, and refunded accurately to avoid errors such as double payments or incorrect balances.

Portrait of Benjamin Boyce
Artificial Intelligence & Technology · November 21, 2026
Share

AI-generated editorial illustration from an imagined camera angle.
AI-generated editorial illustration from an imagined camera angle. Source image: dev.to.

In a rewards program, points are awarded for various events such as completing a lesson or passing a quiz. The program uses an engine that handles these events and ensures that points are credited correctly. For example, a lesson completion event may earn a learner 50 points, but only up to three times a day. This is enforced through rules that define event types, point values, and daily limits. The system also supports custom rules per tenant, allowing schools to adjust point values and conditions based on their specific needs. These rules are stored in a database and applied dynamically during event processing. [1]

To prevent double crediting of points, the system uses idempotency keys. Each event is associated with a unique key based on the event type and a reference, such as the quiz attempt ID. This key is used to ensure that a duplicate event does not result in duplicate points being added. A unique index in the database prevents the second insertion, and the system returns an 'AlreadyCredited' status if a duplicate event is detected. This ensures that even in scenarios where the same event is processed multiple times, only one credit is applied. [1]

Redemption of points is handled with concurrency tokens to avoid conflicts when multiple users attempt to redeem the same reward. A redemption changes multiple values, such as the reward stock and the user's balance, and these changes are saved in a single transaction. If another redemption occurs before the first one is completed, the system detects the conflict and rolls back the second transaction. This ensures that each redemption is processed accurately, and no reward is over-issued or points are lost due to concurrency issues. [1]

The Gamification library, part of the ModelHub ecosystem, was developed as a standalone component from StrideWell, a platform for gyms and coaches. It is now open-sourced as ModelHub.Gamification and is available on GitHub. The library is specifically designed to manage points systems in multi-tenant applications, where each school or tenant can configure its own rules and settings independently. The initial implementation was built for an online learning platform, where each school functions as a tenant, and learners earn points for completing lessons, passing quizzes, and achieving streak milestones. The library is compatible with .NET 8 and .NET 10 and is available via NuGet as ModelHub.Gamification.EntityFrameworkCore. The project includes 80 unit tests and is released under the MIT license. The library is currently in version 0.1, and the author, Kehinde, welcomes community feedback and contributions. This project was first extracted from StrideWell, with the second library being ModelHub.MultiTenancy. The Gamification library is intended for use in applications that require a rewards or loyalty system, with the core functionality focused on the accounting of points rather than the game mechanics, such as leaderboards or UI components. The library is actively being developed and tested, with several issues labeled as 'good first issue' for contributors. The source code and documentation are available on GitHub at https://github.com/modelhub-solutions/ModelHub.Gamification, with a sample API in the /samples directory that demonstrates the learning platform described in the article. [1]

Advertisement

The Gamification library allows for the definition of rules that determine how learners earn points for different events. Each rule is associated with an event type, such as 'LessonCompleted' or 'QuizPassed', and includes parameters like the number of points awarded, limits on how many times the rule can be applied in a given time period, and conditions that must be met for the rule to take effect. For example, a 'LessonCompleted' event can earn a learner 50 points, but with a maximum of 3 times per day, and a 'QuizPassed' event can earn 20 points only if the learner's score is 80 or higher. Schools can customize these rules to fit their specific needs, such as adding a bonus for completing lessons before 7 a.m. or setting a daily cap on the total number of points a learner can earn. The library supports multi-tenancy, allowing each school to define its own set of rules and settings. This is achieved through the use of the PointsProgram and PointsRule classes, which are saved to the database using the SaveRuleAsync and SaveSettingsAsync methods. The rules and settings for each tenant are stored separately, ensuring that they do not interfere with each other. This flexibility allows schools to tailor their rewards programs to their unique requirements without affecting the overall functionality of the library. The library also includes a mechanism for handling concurrency, ensuring that points are credited and spent correctly even in the presence of race conditions. This is achieved through the use of concurrency tokens and unique indexes, which prevent duplicate entries and ensure data consistency. [1]

One of the key features of the Gamification library is its ability to handle the redemption of points for rewards. Learners can spend their points on rewards that are provided by their gym or school, with the redemption process being managed through the RedeemAsync method. This method allows for the allocation of rewards, ensuring that the available stock of each reward is not exceeded. The library includes safeguards against double redemptions, such as concurrency tokens on the Reward.Stock and PointsWallet.Balance fields, which prevent multiple redemptions from occurring simultaneously. If a redemption attempt is made with stale data, the system will roll back the transaction and return an 'OutOfStock' result. This ensures that learners are not charged for rewards that are no longer available. The redemption process is also designed to be safe and reliable, even in the presence of retries or concurrent requests. The library also includes a ledger system that records every change to a learner's points, providing a detailed history of all transactions. This ledger includes entries for earned points, redeemed points, refunded points, and any adjustments made by staff. This level of detail is essential for auditing and ensuring the accuracy of the points system. The ledger is stored in the database and can be queried to provide a complete picture of a learner's points activity. The use of a ledger also helps in managing the fair expiry of points, ensuring that the oldest points are used first when a learner spends points on a reward. This approach ensures that learners are not unfairly penalized for points that have expired. The library also includes a mechanism for refunding points in the case of a canceled redemption, with the refund process being handled in a single transaction to prevent double refunds. This ensures that the points system remains accurate and reliable, even in the presence of complex scenarios and edge cases. The library is designed to be robust and scalable, making it suitable for use in large-scale applications with a large number of learners and rewards. The project is actively being developed and tested, with several issues labeled as 'good first issue' for contributors. The source code and documentation are available on GitHub at https://github.com/modelhub-solutions/ModelHub.Gamification, with a sample API in the /samples directory that demonstrates the learning platform described in the article. The library is intended for use in applications that require a rewards or loyalty system, with the core functionality focused on the accounting of points rather than the game mechanics, such as leaderboards or UI components. The library is actively being developed and tested, with several issues labeled as 'good first issue' for contributors. The source code and documentation are available on GitHub at https://github.com/modelhub-solutions/ModelHub.Gamification, with a sample API in the /samples directory that demonstrates the learning platform described in the article. [1]

In a rewards program, points are awarded for various events such as completing a lesson or passing a quiz. To prevent double crediting of points, the system uses idempotency keys. This approach ensures that even if the same event is processed multiple times, the points are only credited once. Each credit carries an idempotency key, which is made from the event type and a reference such as the quiz attempt ID. A unique index in the database ensures that the second insert is refused, preventing duplicate credits (source ID: 1). [1]

Redemption of points is handled with concurrency tokens to avoid conflicts when multiple users attempt to redeem the same reward. PointsWallet.Balance and Reward.Stock are EF Core concurrency tokens. A redemption changes three things, and they are saved in one SaveChangesAsync operation. If another request gets there first, the concurrency token ensures that the save is rolled back, preventing double redemptions (source ID: 1). [1]

Advertisement

Each user has a wallet with a balance, but the ledger is the real record of their points. Every change is a row in the ledger, including earn, award, redeem, refund, expire, and adjust. The balance only changes together with a ledger row. This provides a clear history of points transactions and ensures that spending on a reward never costs a learner a level (source ID: 1). [1]

Sources

Dev.to

Prepared with AI assistance from the cited sources.

The Cali Reporter newsletter

The stories worth your time.

California, the country, and what comes next. Join our free newsletter for reporting that keeps you informed.

By joining, you agree to receive the Cali Reporter newsletter. Unsubscribe at any time. Privacy policy.

More in Technology

  • Modern Web Guidance 1.0 and Browser Compatibility

    Modern Web Guidance 1.0, announced by Chrome for Developers on November 10, introduces browser compatibility data to assist coding agents in building web features. The initiative emphasizes the importance of fallback…

  • Apache mod_http2 Vulnerability Detection with Nmap

    A new Nmap scripting module has been developed to detect the Apache mod_http2 vulnerability (CVE-2026-119618), addressing the challenges of identifying affected systems accurately.

  • Securing Remote Vendor Access in Industrial Networks

    Best practices for managing remote vendor access in operational technology (OT) networks emphasize controlled access points, multifactor authentication, and time-bound sessions to reduce cybersecurity risks.

Advertisement