Competing spends and repeated callbacks
Database locking, balanced postings, atomic purchase creation and unique financial keys keep retries and concurrent requests from applying the same financial effect twice.
Loading page…
Case study / Payments & messaging
WhatsApp-first top-ups and bills, backed by a double-entry wallet ledger and durable fulfillment.
Full-stack product engineering
Built · provider rollout in progress

Use the arrows, select a preview or swipe. Slideshow is disabled for reduced motion.
01 / The product
SwiftTopUp brings airtime, data, electricity, cable TV and available exam PIN purchases into a guided WhatsApp conversation. I built the backend around verifiable money movement and recoverable provider operations, with React applications for the public website, affiliate workspace and administration. The product includes wallet funding, purchase confirmation, delivery updates and referral reward accounting.
02 / What it does
03 / Engineering decisions
Identity, wallet, commerce, messaging, rewards and administration are modules in a TypeScript modular monolith. The HTTP API and background worker run as separate processes over shared PostgreSQL data. Provider adapters isolate funding, fulfillment and messaging integrations without presenting the system as microservices.
Money is calculated in integer kobo and persisted with balanced account postings. A PostgreSQL row update locks the wallet before balance checks, serializing competing spends. Creating a purchase, recording its debit and persisting its fulfillment job share a database transaction; Redis is not the authority for a wallet balance.
Raw-body signatures authenticate provider callbacks. Provider verification then checks the expected reference, ownership, amount, currency and settled state. Unique idempotency keys prevent a duplicate callback from creating another credit; ambiguous results remain under review instead of guessing who should receive funds.
A durable job stores the provider request ID before the external call. Timeouts and ambiguous responses lead to requery with that same ID, rather than a new purchase or blind provider failover. Leases and stale-attempt checks protect competing workers. Terminal failures use idempotent refunds, while reconciliation recovers unfinished work.
Signed inbound WhatsApp events are persisted and deduplicated before processing. PostgreSQL stores outbound intentions and delivery attempts; Redis Streams wake workers. A successful purchase records the need for a purchaser receipt, and reconciliation repairs interrupted scheduling. A unique outbound key suppresses duplicate scheduling, while an external send can still be repeated if acceptance happens before a local failure is recorded.
Blocking Redis Streams reads replace frequent idle queue activity. The recorded comparison fell from 212.9 to 28 commands per minute; the latter came from 280 commands over ten minutes. That is about 86.8% fewer commands and proportionally lower command-based Upstash cost at the same per-command rate. Pending-message claiming and database reconciliation retain recovery work, so command use is reduced rather than eliminated. Recovery intervals trade promptness for background activity.
04 / The hard parts
Database locking, balanced postings, atomic purchase creation and unique financial keys keep retries and concurrent requests from applying the same financial effect twice.
The requested identity is persisted a recoverable state is held and requeried before fulfillment or refund. This avoids treating every network failure as a failed purchase.
The notification intention is persisted, and missing scheduling is recovered from durable records. Delivery is queued at least once, with idempotent database effects.
05 / What changed
212.9 → 28 commands/minute. Upstash pay-as-you-go charges scale with commands, so the measured activity has a proportional command-cost reduction at an unchanged unit rate. This is a historical rate comparison, not a measured whole-month invoice or a reduction in all infrastructure costs.
Wallet postings, durable jobs, stable provider request IDs, reconciliation and refunds are implemented in the backend. These are source-supported capabilities; no live transaction volume or availability target is claimed.
React applications cover the public website, affiliate referral workspace and administrative operations. Purchases and wallet funding run through WhatsApp and the backend rather than a public web checkout.
06 / Scope & evidence
The public website and affiliate interface are available. Backend capabilities are documented in source; full live funding and fulfillment journeys have not been verified.
07 / Tools used