The only way i can visualize the process is: search the blockchain for all the transactions that have the same source address as the transaction being processed, add them all up (including the trx being processed) to verify they add up to less than or equal to the source transaction amount.
Doing this for every bitcoin transaction sounds horribly inefficient.
How do they really do it?
Miners and all full nodes do check the entire blockchain to validate a new transaction, but they are able to do it efficiently.
As they scan the blockchain starting at genesis, they update a memory structure consisting only of unspent outputs, and index that set. With the index, checking whether a new transaction's inputs have not been spent before is very fast. Currently there are about 8 million unspent transaction outputs.
Bitcoin transactions do not spend amounts from addresses. They fully spend a set of outputs, each from a specific earlier transaction. The reference to an output in an earlier transaction is not by its address: that would be ambiguous. Instead, it is by the numerical sequence of the output inside the earlier transaction.
Some web tools, notably blockchain.info, give the impression that things work differently, but they create that impression on their own, from the actual situation described above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With