Then, two years ago, Larry Krasner ran for district attorney in Philadelphia. Ms. Cabán became obsessed with the race and what it promised, namely a way to abandon fossilized, tough-on-crime rhetoric in favor of calls to upend the system so that harsh consequence and arbitrary punishment were no longer default goals.

Mr. Krasner had practiced both criminal defense and civil rights law; he, too, had been a public defender. In his first year as Philadelphia’s district attorney, city prosecutors opened 6,500 fewer cases than they had the previous year, crucially reducing the number of misdemeanor cases filed and making Mr. Krasner a kind of messiah to advocates for criminal-justice reform.

Other public defenders have since seen the wisdom of switching sides, so to speak. Last year Geneviéve Jones-Wright ran for district attorney in San Diego, arguing that too few of her clients had received recommendations for diversion programs from the district attorney’s office that would keep them out of the courts. She lost to a prosecutor but received the support of George Soros.

Currently, Chesa Boudin, San Francisco’s deputy public defender, is running for district attorney there. Mr. Boudin is the son of Kathy Boudin and David Gilbert, members of the Weather Underground who were sent to prison in conjunction with the 1981 Brink’s robbery. He is campaigning in part on the promise that he will reduce high rates of recidivism and help those arrested find jobs and pursue their education.

In addition to the backing from Ms. Ocasio-Cortez, Ms. Cabán has the advantage of going up against a chief rival who has been a career politician, with all the fustiness that that implies. Ms. Katz has neither been a defense lawyer nor a prosecutor; as a member of the New York State Assembly in the 1990s she voted to reinstate the death penalty, a position she now disavows.

Should Ms. Cabán win the Democratic primary next month, she would presumably serve as a role model for other young progressives to effect change from the inside. The problem, though, is that vision will get you only so far. The position of district attorney requires running a huge office, staffed with people who have grown set in their ways, often over decades.

Mr. Krasner, who is in his 50s, came to the Philadelphia district attorney’s office and quickly fired people. He goes around the country as an evangelist for reform-minded prosecutorial work, often trying to talk aspiring public defenders to embark on his line of work instead. (This has angered some in public-defender circles.)