Race conditions can occur when using multiple database transactions in a single API request, especially in systems with high concurrency. This post outlines the challenges faced by the Merpay Balance team, who encountered race conditions while processing debt repayments. They evaluated solutions such as rollback, lock mechanisms, and merging transactions, ultimately choosing a lock mechanism to ensure only one request processes repayments at a time. The implementation details, including challenges and considerations, are shared for developers facing similar issues.
Table of contents
BackgroundMultiple DB transactions in one requestOne problem fixed, but another came – Race conditionPossible SolutionsChallenges of lock mechanismOther perspectivesSummarySort: