Designing a financial wallet backend involves taking on a critical responsibility: ensuring that every transaction is recorded atomically, consistently, and immutably. No concurrency error, network retry, or infrastructure failure can cause money to be created or lost. This article addresses the architecture of a wallet core using PostgreSQL as the source of truth, Node.js for transfer logic, and Kafka to notify peripheral services. It is an approach that prioritizes financial integrity through double-entry accounting, row locking, and idempotency keys. The described pattern is applicable to payment systems, investment platforms, or any application that manages balances. At Q2BSTUDIO, as a company specialized in custom applications, we apply these principles in every project that requires reliable handling of sensitive data.
The foundation of the design lies in a relational schema where the balance of each account is a value calculable from immutable accounting entries. Storing money in smaller integer units (cents) avoids rounding errors from floating-point types. Each transfer is executed within a database transaction: first, an attempt is made to insert a transfer record with a unique idempotency key; if it already exists, the original result is returned without modifying balances. Then, both accounts are locked in a set order (by sorting IDs) to prevent deadlocks, the source account is verified to have sufficient funds, balances are updated, and two accounting entries (debit and credit) are recorded. Only after confirming the transaction is an event emitted to Kafka. This approach ensures that no retry duplicates a movement and that no failure after the commit causes the operation to be lost, although for full reliability it is recommended to use the transactional outbox pattern, where the event is persisted in the same database before being published.
Integration with Kafka allows the rest of the system to react asynchronously: notifications, analytics, fraud engines, or AI for businesses can consume events without slowing down the main flow. For production environments, consumers should also be idempotent, as Kafka guarantees at-least-once delivery. Additionally, periodic reconciliation between the stored balance and the sum of accounting entries allows early detection of any deviation. At Q2BSTUDIO we integrate aws and azure cloud services to deploy these systems with high availability, and we apply cybersecurity at every communication layer. We also develop AI agents to automate anomaly detection and offer business intelligence services with power bi to visualize the portfolio status in real time. We combine artificial intelligence with custom software to build robust and scalable financial platforms, tailored to each client's specific needs.

.jpg)

