Похожие чаты

Hello, I'M working on an app involving money. Every money involving action

creates a record, from which the overall user's balance can be calcuated.
There are many ways for the users to create these records, inside and even outside the application.
I want to make sure the new records won't ever result in negative balance for the user (because that means they used up more than they had, obviously).
If my application gets two requests at the same time, it might allow 2 decreasing records as the balance calculated for both requests was the same.

How do I deal with a problem like this?
I'm aware of the locking, but I feel like it's not reliable enough.
The solution I'm thinking of right now is creating something like a chain of any actions involving money.
Any new action would need to reference the previous action and this reference should stay unique for every user seprately.
If there's an attempt to append 2 records that reference the same previous action, then only one goes through.

However, I'm struggling to think of a solution for such a system.
Can anyone show me how the integrity of any financial data is normally achieved?
Or at least, is there any additional information on the solution I currently have in my head?

2 ответов

10 просмотров

Are you trying to implement a blockchain?

You need to have a database that is transactional and hence allow you to cancel operations if they result in an invalid state. To be precise, they need to be able to consider every balance action as an atomic operation

Похожие вопросы

Обсуждают сегодня

Всем привет! Имеется функция: function IsValidChar(ch: UTF8Char): Boolean; var i: Integer; ValidChars: AnsiString; begin ValidChars := 'abcdefghijklmnopqrstuvwxyzABCDE...
Евгений
44
Ну вот просто даже давайте вот как. Какой нибудь конкретный кейс, можете в пример привести, где бч работает и приносит прикладную пользу, а не просто что бы было? Не крипту.
Alexander Andreev
22
объясните пожалуйста, почему функция не работает должным образом? вроде должно брать активное окно сравнивать его размер с размером экрана, и если есть совпадение = true прове...
JF
12
For all those that keep asking why no pump? why this ? and why that...? Please close ur ewt chart and open 2 others - TOTAL (total mc) and BTC.D (btc dominance). Maybe BTC a...
Inn3r_G
19
"Since pnut can flip FTM easily, I'm swapping my FTM to pnut and hoping for a easy x5-x10" Perfect recipe for disaster. NFA but chances are, you'll end up as exit liquidity ...
C. A.
7
Ready for some fun AND a chance to win TKO Tokens? Join us for exciting minigames in our Telegram group! 🕒 Don’t miss out—games start on today 25 October 2024, at 8 PM! Ge...
Milkyway | Tokocrypto
255
AMD status update? No longer in the plan but something might be around the corner later on Chinese partner? No longer in the plan. This market does not seem to be the top ...
Ben
6
207$ but only received 170$. what the hell?
htt
10
да кстати заметил всюда почему то всех сюда прёт, ни в одном чате столько ботов не прёт как сюда.. Может чота надо доработать?
REDis
15
Мне вот любопытно. Уже сколько времени имею соблазн купить макбук, ибо подозреваю что очень уж удобен будет в связке с другой техникой от эпл которая у меня есть, да и сам по ...
Not Yeromin
14
Карта сайта