Skip to content
JournalTORIS / FIELD NOTES

← Blog Project notes

Awarding Points Was a State Transition, Not Addition

Handling point payouts and deductions across content being made public, private, or deleted, and why prior state and processing history came before amount calculation.

3 min read Read the Korean original

Joohwan Yu · Founder, Full Stack Developer

Toris · Published

Contents

I worked on a feature that awards points when content is made public and deducts them, depending on conditions, when it is made private or deleted. By the feature’s name, it is addition and subtraction. But what was actually hard was not how much to add, but judging whether this particular change is eligible for a payout.

What you miss if you look only at the current state

From the fact that content is public alone, you can’t tell whether it’s OK to award new points. It differs whether it was published for the first time, whether already-public content was edited, or whether it was made public again after being private. Deduction is the same: if you execute it only because the content is currently private, it may not match whether a payout happened before.

At the time, we handled these differences in SQL conditions and service branching. Even if you can split the entry points for payout and deduction, as with newAccumulatePoint and newDeductPoint, the policies the two methods look at had to match each other. If you fix only one side, the opposite action doesn’t return things to the original state.

The table I would build first if designing again

ChangeQuestion to check first
Private → publicIs this publication eligible for a new payout?
Public → publicIs it a content edit, or a new payout event?
Public → privateIs there a payout history to cancel?
Private → deletedWould it deduct again something already deducted?

This table does not disclose the company’s detailed policy at the time; it is a set of questions for reviewing the same type of feature. Rules for payouts on re-publication may differ by policy. That is why you have to decide before writing code.

Blocking the button is not enough

Even if you block consecutive clicks on the front end, the possibility remains that the same request comes in again. If I were doing it now, I would first decide an identifier for which event counts as one payout, and then review how to handle duplicates at the storage stage. Regardless of what was actually applied, it is clear that from the balance alone it is hard to explain whether the same event was reflected twice.

I can’t say that every path at the time was automatically verified. So what I want to leave in this retrospective is not the perfection of the implementation but the change in how I think. If I take on a points feature again, I’ll write down “which state change counts as one payout?” before “where do I call the payout function?” The amount was a value attached to that event.

Related post: Experience working full-stack on an operating project

Advertisement