How does routing work in IPFS?

I’ve been following the proto.school course. CIDs and Merkle DAGs I’ve grasped pretty well. In a system with a small number of nodes where it’s feasible for every node to be connected to every other I can see how if you want to find file ABC you can just ask all the nodes who has it, or there is a table mapping CIDs and peers.

How does this scale to millions of peers, where a peer might be any number of peers away from you? If I am looking for file ABC, how do I then traverse the network to get to the identity/location of a peer who I can make the request to?

I understand this is related to DHTs, but I haven’t found a resource that explains them in a way I’ve understood yet.

The DHT. See How IPFS works | IPFS Docs.

IPFS uses a Kademlia-type DHT. There are many resources on how it works in the interwebs.