This has already been asked here several times. See this example for a short but helpful answer. This approach is still the most common way to go.
Another (hacky and inefficient) but much simpler way would be to just set up some monitoring (be it the sophisticated icinga/nagios/etc. way or a simple curl or service check cron job) and if it fails switch the routing. This would still have at least the downtime of the time needed for the check to notice this event (few seconds maximum) plus the DNS entry TTL (generally at least minute range).
However, I‘m just mentioning this for creativity and simplicity, this is far away from a production-level solution.