The problem
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.
Key decisions
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.
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.
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.
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
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.