An idempotent store credit ledger: every reward is credited exactly once, even when the same webhook is delivered twice.
Balto customers earn store credit when they subscribe, refer a friend or review a product, then spend it at checkout or on their next subscription box. I built the backend behind all of it: small, single-purpose services on Google Cloud.
The hard part is that Shopify and Recharge deliver webhooks at least once, so the same event can arrive twice. Every event carries an idempotency key checked against the ones already processed, so a duplicate never pays out. The ledger is append-only, and a nightly reconciliation job compares every balance with Shopify and flags any drift.
Every way a customer earns or spends credit.
Cashback on subscription orders, credited only once the order ships, so cancelled orders never pay out.
Referral links: the friend gets a one-time discount code and the referrer earns credit. Unused codes are cleaned up automatically.
Credit for product reviews collected through Loox.
Spending credit at checkout, with refunds that return credit to the customer.
Redeem or auto-redeem from the customer portal, applied before the next subscription charge.
Credit that expires on schedule, admin tools for manual adjustments, and a sync for credit issued outside the system.
