All case studies

Case study / Distributed systems

1M users, zero double credits

Exactly-once payments with ordered queues and idempotency, and 65% less cloud spend.

The problem

1M+users
64%day-one retention
~65%lower monthly spend
0manual console changes in production

Live voice and video lobbies, real-time gifting, and real money moving every second, in fiat and on-chain tokens. Two failures cost real money: a payment credited twice, and a platform that goes down during an attack. A third failure was slower: the cloud bill grew faster than the business.

Architecture

A NestJS core API and a Node.js lobby service on ECS Fargate, behind CloudFront and AWS WAF. SQS FIFO carries financial events. Lambda takes in webhooks. MongoDB Atlas is the system of record, and Firebase RTDB carries live lobby state. All of it is defined in AWS CDK.

REQUEST PATHMONEY PATHClientsweb · mobileCloudFront + WAFrate rules per routeCore APINestJS · chain adapterLobby serviceNode.js · Agora RTCFirebase RTDBlive lobby stateMongoDB Atlasledger · unique txreads / writesChains + StripeEVM · Solana · TONLambda ingestwebhooks · chain eventsSQS FIFOordered · deduplicatedConsumeridempotenteventsenqueuein ordercredit once
Money never takes the request path. Every financial event goes through the ordered queue, and the consumer credits each transaction once, even when the same event arrives twice.

Key decisions

Decision 1

Exactly-once money, at two layers

SQS FIFO gives ordering and deduplication for financial events. Database-level idempotency is the second guard: one credit per on-chain transaction, no matter how often a message arrives. Replay and double-credit attempts fail at the data layer.

Decision 2

One payment interface for every chain

EVM (Ethereum, Polygon, Abstract L2), Solana, and TON sit behind a single adapter. It hides each chain's SDK, transaction model, and finality rules. The rest of the platform takes payments and runs custodial wallets with no per-chain branches.

Decision 3

Defense at the edge, by endpoint group

WAF rate-based rules for each group of endpoints, IP reputation lists, and autoscaling tuned for sudden spikes. Money paths got stricter limits than the rest. The platform stayed up through sustained DDoS and brute-force campaigns.

Decision 4

Make the data layer do less

Live lobbies synced more data than any screen needed. Narrower writes and listeners cut Firebase cost by about 87%. On MongoDB, aggregation rewrites and covered queries took the cluster from M30 back to M10 with no performance loss.

Results

Before (range)After$0$1k$2k$3k / moFirebaseFirebase before: $2,000–3,000 / moFirebase after: $300–400 / mowas $2,000–3,000 · now $300–400AgoraAgora before: $1,100–1,500 / moAgora after: ~$480 / mowas $1,100–1,500 · now ~$480AWSAWS before: $900–1,200 / moAWS after: ~$380 / mowas $900–1,200 · now ~$380MongoDBMongoDB before: $600–800 / moMongoDB after: ~$220 / mowas $600–800 · now ~$220
Monthly spend per service. The largest drop came from the realtime layer, where narrower writes and listeners cut Firebase by about 87%.

Total infrastructure and third-party spend fell by roughly 65%, with no change to the user experience.

Tradeoffs

FIFO queues give up raw throughput for order, so they carry financial events, not general traffic. One adapter for three chain families means a new chain takes adapter work, but no feature work.