Project
Distributed Offline Payment System
Distributed payment system that works with zero internet connectivity
A distributed payment system where UPI payments work even with zero internet connectivity. Edge nodes accept payments fully offline, queue them in local encrypted storage, and sync to a central backend when online — settling every payment exactly once with cryptographic tamper-detection.
Key highlights
- Designed a hybrid RSA-OAEP + AES-256-GCM encryption pipeline where each payment packet is individually encrypted — any single-bit modification in transit is detected and rejected via the AES-GCM auth tag
- Implemented exactly-once settlement using Redis SET NX EX as an atomic idempotency gate, backed by a unique index on packet_hash in PostgreSQL — the same payment delivered 10 times settles exactly once
- Built the transactional outbox pattern on edge nodes: payments are written to a local H2 queue and wallet balance atomically, then flushed to the backend with exponential backoff (1s → 2s → 4s) preventing thundering herd on reconnect
- Prevented double-spending in offline mode via pre-funded wallets — backend locks a spending allowance per edge node before it goes offline; every offline debit uses an atomic compare-and-set against the local wallet, refusing payments at the device level when exhausted
- Achieved concurrent multi-node safety with pessimistic DB locking on Account rows during settlement + Redis idempotency as the fast first gate, ensuring zero race conditions across simultaneously syncing edge nodes
- Integrated Micrometer + Prometheus metrics with a live Thymeleaf dashboard, rate limiting via Bucket4j (60 req/min per node), and structured logs — full production observability out of the box
Tech stack
JavaSpring BootPostgreSQLRedisPrometheusH2DockerThymeleaf