During the winter of your senior year of medical school, in the US/Canadian system, you interview for your specialty training programs at several places that interest you. There’s a computerized system that matches applicants with programs, based on the preferences of both and blinded to both (you’ll never know if you were the top pick of your residency, and they’ll never know if they were your fourth choice). “The Match” is published in the spring, and off you go to your residency. That’s true for all specialties, not just IM, but surgery, family practice, pediatrics, etc.