I must analyze whole blockchain and hundred of millions addresses?
kind of. you must keep a list of all "unspent outputs" - it's usually called UTXO database.
alternatively you can download the raw translations (that the input refers to) from one of the block explorers.
it's actually secured - you just need to verify the downloaded transaction against the ID that is being spent.