If you’re a medical student or recently became a doctor, no need to read further. I’ll be describing one of the most stressful and pivotal moments of your professional life, and you probably already know the gory details.

For the rest of you, know this: Your future doctor could be among the more than 34,000 medical students whose fate is about to be handed over to an algorithm.

Over the past couple of months, medical students have been interviewing for residency positions at hospitals around the country. But unlike traditional job interviews, there’s no offer at the end of these meetings.

Med students and hospitals are currently ranking their top choices from these interviews. These lists will be sent to the National Resident Matching Program (NRMP), for a process known as the Match. The rankings get dumped into an algorithm, which determines where the students will do their residencies — three to seven years or more of supervised training, usually in a hospital. Since you can’t get a license to practice medicine in the United States without completing a residency, this is a high-stakes game.

The algorithm is based on the work of Lloyd Shapley and David Gale, American mathematicians and economists known for their contributions to game theory. Although it has many applications (it’s currently used to find recipients for organ donations, and to assign high school students to schools in Boston and New York), it’s easiest to explain using an example from the paper Shapley and Gale published in 1962: how to happily marry off everyone in a community (albeit one that’s made up of equal numbers of women and men who all want to be in heteronormative relationships).

It works like this: Each of the women proposes to her first-choice man, and he rejects or accepts. Women still without a partner approach their second-choice man (the women can propose to men who have already accepted an offer, and the men can choose to reject an initial proposal if a better offer comes along). This continues until there are no women left who want to propose to a man.

Shapley and Gale showed that while this process leads to a stable system, it slightly favors the women; since they are doing the proposing, they have a slight edge over the men. Some women will wind up with their first-choice men — the best possible outcome for them — because they did the asking, while no woman will end up with a worse choice than she would have if the men had done the asking.

When the algorithm is applied to medicine, students and residency programs replace women and men. Instead of marriage proposals, we have students applying to residencies.

Before the NRMP Match, which was founded by students, residency positions were filled with a hodgepodge of methods. Sometimes that meant early offers (to students in their first years of medical school, before a hospital could know their qualifications or what specialization they might choose, and leading to swift replies from students who didn’t know what their other offers might be), and sometimes it meant students rejected hospitals’ offers so late it was hard to find suitable replacement candidates, among other challenges. The Match offered a more coherent and fair process.

There were, however, a couple of problems with the initial Match algorithm. First, it couldn’t accommodate med student couples who wanted to be placed together. Residencies often involve relocating, and always involve working long hours; many couples were choosing to try and find positions outside the Match. Second, the program originally had the hospitals doing the proposing, giving their preferences a slight edge over students’.

By 1997, the NRMP had updated the algorithm to address both these issues. Mona Signer, president and CEO of the organization, told me that changing who did the proposing had little effect on the outcome of the Match, but has been important for students’ perceptions.

If the algorithm’s success is measured by how well it places U.S. students graduating from traditional allopathic medical schools, then it’s been a relative hit. Last year, 94.4 percent of U.S. fourth-year medical students who participated in the program were assigned a residency, in line with the 92 to 94 percent who have gotten a spot historically. Around 80 percent of those who matched received a residency at one of their top three choices in 2014. It’s worth noting that since the number of applicants has gone up in most years, a steady percentage of matches means the raw number of students who don’t match has increased.

(The situation is different for international medical graduates and U.S. students who study abroad, who had a match rate of 49.5 and 53.0 percent respectively last year.)

And while the algorithm has been good at getting medical students into residency programs, the entire process is not without its problems.

The conventional wisdom is that students who list more potential residencies have a better chance at a match, since the lists of students who do match average twice the length of those who don’t. Students are adding more and more residency programs to their lists; the average number of programs listed by students who ended up with a match has grown to 10.3 from 7.4 over the last decade. Students can send up to 20 applications for the baseline fee. Many send double that, and can end up going on a dozen interviews, paying for a hotel and flight for each. The costs add up quickly. (Sallie Mae, the country’s largest lender of student loans, offers medical students loans up to $20,000 specifically to cover the costs of interviews and relocation in the case of a match.)

It’s understandable that students would worry the Match has become more competitive, and spend thousands of dollars interviewing at dozens of places as a result. More than 20,000 students graduating from U.S. medical schools and an additional 10,000 to 15,000 foreign medical students and U.S. students studying at medical schools abroad are vying for spots in residency programs this year.

But according to Signer of the NRMP, all these interviews don’t necessarily help a student match. She said the algorithm doesn’t favor a longer ranking list. Instead, she thinks the increased number of applications may be a disservice to both students and programs. “The programs can’t possibly interview all those people, so they screen them using some criterion like test scores,” she said, referring to the large number of applicants many programs must sift through. “Perfectly suitable applicants never make it past the gate.”

Signer says students should be honest with themselves about how competitive they are and target applications at specialties and programs they are likely to get into. The annual “Charting Outcomes” report provides detailed information on how competitive different types of residencies are.

The American Association of Medical Colleges (AAMC) has been sounding alarm bells for years that there won’t be enough residency positions for all the doctors graduating from U.S. schools. As the demand for doctors grows with the Medicare rolls and the influx of new patients under the Affordable Care Act, they’ve increased the number of matriculants by nearly 30 percent since 2006.

The majority of residency programs are at least partially funded by a provision of Medicare, and that funding has been capped since 1997. Several bills have been introduced to raise the limits over the years, but none has made it through the chokehold of Congress. Instead, the funding has taken hits from provisions in the Affordable Care Act and budget cuts during the recession.

According to Atul Grover, the AAMC’s chief public policy officer, the number of residencies is growing at a slower rate than the number of people enrolling in med school. He says he’s not sure when those two points will meet, but the smaller ratio of U.S. medical graduates to residency positions is scary for graduating seniors, and likely driving up the number of interviews they feel they need to be competitive.

“I think the challenge right now of having to apply to so many places is not the Match’s fault, it’s Congress’s fault and the cap they put on residencies 18 years ago,” he told me. “Students are getting more and more panicked about being able to get a spot. Right now there are enough positions, but the lines are coming so close between the two.”

It’s unclear whether Grover is right. So far, a crisis hasn’t hit. Teaching hospitals have increased some funding for residency programs, and positions have opened up in rural and critical-need areas that aren’t subject to the cap.

Signer cautioned that, for the moment, there are plenty of residency spots to go around, at least for graduating U.S. seniors. She doesn’t see that changing anytime soon, and says the most important thing for students is to look at the data, and to be realistic about their options.