Menu

Post image 1
Post image 2
1 / 2
0

Two billing bugs that looked fine until production proved otherwise

DEV Community·nareshipme·30 days ago
#CGbJVMxd
Reading 0:00
15s threshold

Billing code is the most dangerous place to have subtle bugs. It rarely crashes — it just silently does the wrong thing. Here are two we found and fixed in ClipCrafter , an AI video clip extraction tool. Bug 1: The usage counter that lost data under load We track how many seconds of video each user processes per day to enforce plan limits. The original increment looked like this: const { data } = await db . from ( " users " ) . select ( " daily_usage_seconds " ) . eq ( " clerk_id " , clerkUserId ) . single (); const next = ( data . daily_usage_seconds ?? 0 ) + seconds ; await db . from ( " users " ) . update ({ daily_usage_seconds : next }) . eq ( " clerk_id " , clerkUserId ); Enter fullscreen mode Exit fullscreen mode This is a textbook read-modify-write race.…

Continue reading — create a free account

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

Read More