This is a driver’s worst nightmare. I had a lot of dreams where the brakes couldn’t stop my car and I couldn’t do anything.
Fortunately for us, this is very hard to happen in the real life. Why? First of all because the brake system is at least 3 times redundant. You have two separate hydraulic brake circuits and a mechanical one. The two hydraulic circuits are commanded by the brake pedal and the mechanical circuit is commanded by the handbrake. Some cars have 3 hydraulic circuits and a mechanical one. So, you don’t have to worry about. Second of all, the braking system is a very simple one and if checked regularly, it is very improbable for it to fail.
But what to do if you still encountered a brake failure? First of all it is very hard because most cars require to press the brake before starting the engine and you would sense immediately that something is wrong with it. Nevertheless, if your hydraulic brakes failed, you still have the handbrake (emergency brake). If this doesn’t work either, get step by step from superior gears to inferior ones, reduce the speed of the car, and eventually, put it in neutral and it will stop by itself according to the rolling resistance.
Again, this is a very unlikely situation but if it happened, now you know what to do.