Menu

Points += 50 is a bug: a rewards engine for .NET that never pays twice
📰

Points += 50 is a bug: a rewards engine for .NET that never pays twice

DEV Community: dotnet·Kehinde Ademola Olosunde·22 days ago
#lXojhau3
#devtodotnet#devto#dev#points#event
Long article (1917 words) — no AI summary yet.
Reading 0:00
15s threshold

Every app with points has a line like this somewhere:

learner . Points += 50 ; await db . SaveChangesAsync ( ) ;

Enter fullscreen mode

Exit fullscreen mode

It looks harmless. Then real traffic arrives:

The mobile app times out and retries "lesson completed". The learner gets 100 points.

A message queue delivers the same event twice , which at-least-once delivery is allowed to do. The learner gets 100 points again.

The learner double-taps "Redeem" on the last tutor session. Two requests both read "1 left", and both succeed.

Staff cancel a redemption, the request is retried, and the points are refunded twice .

None of these is unusual. Once points can buy something they behave like money, and code that handles money needs to be exact.

I'm adding a rewards programme to StrideWell, the platform for gyms and coaches I'm building. Members earn points for sessions and streaks, and spend them on rewards their gym pays for.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.