Back to feed
Dev.to
Dev.to
7/10/2026
Billing a Bulk Endpoint Where Any Row Might Be Free

Billing a Bulk Endpoint Where Any Row Might Be Free

Short summary

A solo SaaS builder details the billing architecture for a bulk GSTIN verification endpoint where some rows are free (cached, not-found, invalid) and billable rows can't be identified until after paid API calls. The core challenge is reserving credits atomically per-item rather than per-batch to avoid race conditions where concurrent requests oversell credits. The author also covers a SQLite thread-safety bug from offloading DB writes to worker threads and a CSV formula-injection guard for Excel exports.

  • Atomic per-item credit reservation prevents race conditions that batch-level read-then-write billing introduces
  • SQLite DB writes must stay on the event loop; only slow HTTP calls should be offloaded to threads
  • Excel export values starting with =, +, -, or @ must be prefixed with a quote to prevent formula injection

Generated with AI, which can make mistakes.

Is this a good recommendation for you?

Comments

Failed to load comments. Please try again.

Explore more