| ▲ | tlb 11 hours ago | ||||||||||||||||
It's not necessarily shared. You could assign a single thread to own the account balances, reading requests from a message queue. That probably scales better than locking. A single thread can do several million transactions per second, more than the entire global financial system. | |||||||||||||||||
| ▲ | xmcqdpt2 9 hours ago | parent | next [-] | ||||||||||||||||
And in a green threading system like Go or Scala Cats, the balances thread isn’t a thread at all, and it will run in the same thread as the transfer caller when the call isn’t contended, so you don’t even have a context switch. | |||||||||||||||||
| ▲ | kreetx 8 hours ago | parent | prev [-] | ||||||||||||||||
What if you want to compose an action on a balance with something else? (That is what the OP is about) Also, with a queue, you've moved the shared state elsewhere, namely, into the queue. | |||||||||||||||||
| |||||||||||||||||