Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Upgrading must not shrink anyone's share, so I checked 27,404 ways to split a day, and the rounding never fires

Nakodo gives each plan a number of new outreach emails a day: Free 10, Pro 25, Business 75. On plans with more than one campaign, that day is split between the campaigns, and each campaign owns a share the user chose. When someone upgrades, every share has to grow with the day, or the user pays for 75 and gets 25 spread the same way. The function that does it is small enough to quote whole:…

Nakodo's plans allocate a specific number of outreach emails per day, with Free receiving 10, Pro 25, and Business 75. When a user upgrades, the shares must proportionally grow to match the new day, or the user ends up paying for a higher plan with fewer emails. The function responsible for this calculation, widenShare, ensures the new shares never exceed the new day limit and rounds down to prevent any share from increasing.

A test was conducted to examine the impact of rounding on the email distribution between plans, specifically comparing Business to Pro. Over 27,404 possible splits, no share shrank, and the floor function never threw away any proportional emails in any of the splits. The only instance where emails were lost was when converting a Pro plan with 25 emails to a Business plan, where rounding resulted in losing up to two emails in the worst-case scenario.

The code is deemed correct and has a unit test, but the rounding could be considered dead code since it only affects a specific case that isn't currently used in production. The key takeaway is that testing the invariant, rather than the function itself, is more crucial for ensuring no customer loses emails during an upgrade.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

More from Dev.to on urgent.news

Report a problem with this story

Get the day's news by email. Daily, weekly or monthly. Sign up

More in Tech

More from Wednesday, 2 December 2026 →