It refers to horse racing. You can place a lot of money on a horse and hope that it wins. The expression "we have a lot riding on this" refers to the stake or risk you have taken in the outcome of a certain venture. (the horse race being this venture).
Nowadays, it refers to any kind of risk where you have staked something, be it money, reputation, or anything you hold as valuable, on the outcome of another event.
For an example, "I have raised some money by re-mortgaging my house to make this business venture work, I have a lot riding on it". It means that if my business fails, I will lose the money invested, the bank will re-call the loan and I will lose my house.