Selling AI credits sounds simple. At first, the architecture usually looks something like this: Stripe Checkout a credits column in your database deduct credits when the user runs an AI action done And honestly? For early testing, this often works perfectly. Until production traffic starts growing. Then suddenly you start dealing with: duplicate webhook events retries stale subscription state delayed payments duplicated credit consumption users with successful payments but no access access drift between Stripe and your backend At that point, AI billing stops feeling like a payments problem. It starts feeling more like distributed systems engineering. The “simple AI credits system” Most AI SaaS products start with something like this: User buys credits with Stripe Stripe sends a webhook Backend increments credits User consumes credits during usage Simple enough. For example: await db . users . update ({ credits : user .…