Forgive me if this is a silly or extremely basic question, but I was wondering how the logistics of interest and dividend payments are handled on assets, such as mortgages, bonds, stocks, etc. I personally do not currently invest in any of these, but as I understand it, most of these assets are issued on the "primary market", i.e. the homeowner gets a mortgage loan from a bank, an individual buys a Treasury bond from the government, or someone buys shares in a company during its IPO. As a result, interest payments and dividend payments would straightforwardly go to whoever they are owed.
However, as I understand it, a lot of the time, the buyer of these assets, after an (often short) period of time, turns around and sells it in the secondary market, where it is then traded and gets passed around ad infinitum.
Now during this process, what happens to the stream of interest and dividend payments; do they automatically get updated to whoever the new owner is?
What if the owner is some high-frequency algorithm that buys and sells bonds and stocks in fractions of a second?
When the company decides to pay dividends, does it literally track down every single owner of that stock and deposit x cents per share in that person's bank account? (This sounds absolutely absurd and seems like it would be a logistical nightmare).
For the homeowner, I'm assuming he / she still makes mortgage payments to the initial bank they got the mortgage from, even if the bank no longer "owns" the mortgage. In this case, does the trader on the secondary market who owns the mortgage also come back to that bank to collect his interest payment?
In general, when these assets are traded on the secondary market, to whom do the interest and dividend payments go, and who handles the logistics of making sure these streams reach the right people?