Financial Custody: Managing Balance and Portfolio with Eventual Consistency
The article discusses the design and implementation of the Broker Wallet API, a critical financial custody service that manages investor funds and assets by reacting to order lifecycle events through Kafka. It emphasizes the importance of maintaining accurate balances using eventual consistency, with mechanisms like blocking funds during pending orders to prevent overdrafts. The system is built using Java, Spring Boot, MySQL, Redis, and Kafka, ensuring reliable transaction handling and real-time portfolio valuation.
- ▪The Broker Wallet API ensures correct management of user funds by listening to Kafka order events rather than accepting direct commands.
- ▪It prevents negative balances by reserving funds when an order is pending, using a blockedBalance mechanism that subtracts from available balance.
- ▪The service uses eventual consistency and reacts to PENDING, FILLED, or REJECTED order events to reserve, settle, or refund funds accordingly.
- ▪Key technologies include Java 21, Spring Boot 3.5.11, MySQL with Flyway, Spring Kafka, Redis for real-time pricing, and SpringDoc for API documentation.
- ▪The data model centers on Account, Position, and WalletTransaction entities to track balances, holdings, and audit logs.
Opening excerpt (first ~120 words) tap to expand
try { if(localStorage) { let currentUser = localStorage.getItem('current_user'); if (currentUser) { currentUser = JSON.parse(currentUser); if (currentUser.id === 1452979) { document.getElementById('article-show-container').classList.add('current-user-is-article-author'); } } } } catch (e) { console.error(e); } Roberto de Vargas Neto Posted on May 1 Financial Custody: Managing Balance and Portfolio with Eventual Consistency #springboot #java #microservices #kafka Hey folks! Continuing the My Broker B3 series, we've reached one of the most business-logic-rich services in the ecosystem: the Broker Wallet API. In previous posts we built the B3 infrastructure (market price sync and matching engine). Now we enter the financial core of the broker.
…
Excerpt limited to ~120 words for fair-use compliance. The full article is at DEV.to (Top).