This is done via ASNs (Autonomous Systems Numbers), like 32150 (my old ASN). Each hop along the way gets their ASN tacked on. It's like a flood-fill to all the BGP routers in the world.
When you "traceroute", you see IP hops along the way, but the ISPs routers choose links based on this list of autonomous paths (among other things). Basically, a AS-level traceroute is built into the BGP routing information. At it's most basic, a path is selected based on the shortest AS path (traceroute, but at the organization level rather than IP level); the fewest number of networks the traffic has to traverse.
If a link goes down (either because of a network failing, or because of administrative reasons), traffic will eventually switch over to another way of reaching the destination. You can also do things like pad the AS path with multiple copies of your AS to cause traffic to switch to another link more frequently, as a kind of primitive load balancing.