Sanders and Trump supporters complain that they deserve more delegates. (Seth Wenig/AP)

Matthew Dallek, an assistant professor in George Washington University’s Graduate School of Political Management, is a co-author of “Inside Campaigns: Elections Through the Eyes of Political Professionals” and the author of the forthcoming “Defenseless Under the Night: The Roosevelt Years and the Origins of Homeland Security.”

Watching it unfold from his home state of New York, Donald Trump was aghast when Ted Cruz picked up all of Colorado’s 34 delegates at the state’s Republican convention last weekend. As his grip on a first-ballot nomination slipped away, Trump lashed out: “The system, folks, is rigged. It’s a rigged, disgusting, dirty system.” On the other side, Jeff Weaver, Bernie Sanders’s campaign manager, vowed to contest Hillary Clinton’s nomination at this summer’s Democratic convention — presumably because the system of superdelegates, among whom Clinton leads 469 to 31, is also rigged. Pundits agree, too: “Why does the Democratic Party even have voting booths?” MSNBC’s Joe Scarborough railed this past week, after watching Sanders win Wyoming’s caucuses only to receive fewer of that state’s delegates (including superdelegates) than Clinton did.

It’s true that both parties’ nominating systems are covered in warts. State caucuses tend to be held at night in winter, require at least an hour of voters’ time and result in low-turnout elections dominated by hard-core activists. Individual states on the Republican side have autonomy to apportion delegates as they see fit (take Colorado, which Cruz won through a seemingly undemocratic statewide GOP convention), while Democrats have a convoluted allocation process, leading to outcomes like the one in Wyoming, where Clinton lost the caucuses by nearly 12 percentage points yet took the same number of pledged delegates as Sanders. Iowa and New Hampshire vote months before Texas, New York and California do, giving two lily-white states disproportionate power to winnow the nominating field. And theoretically, unpledged delegates in both parties could tip the scales in favor of a candidate who lost the popular primary vote, enabling elites to thwart the electorate’s will.

A system that favors rich insiders and the strategists best able to game it, the critique goes, is hardly democratic. Party leaders, appearing to recognize this, have offered up only a meek defense of their respective nominating processes, saying, essentially: Rules are rules, these have the virtue of transparency, and everybody must abide them.

But it’s time for a robust defense of the nominating process. The current system — a potpourri of caucuses, primaries, state conventions, superdelegates and pledged delegates — is far superior to how nominees were chosen for much of the 20th century. It gives everyone a stake and deprives anyone of too much power, balancing competing democratic goals and legitimate party interests.

Before 1972, party leaders had nearly unrivaled sway in determining the nominees; a relatively small handful of mostly white men ultimately decided who would be on the November ballot. In 1948, Republican nominee Thomas Dewey received a meager 11.58 percent of the primary vote yet carried the GOP’s banner that fall. In 1960, the Democratic Party held only 16 primaries, and John F. Kennedy had to persuade state party leaders to back him at the nominating convention in order to secure the nod. In 1968, antiwar candidates Robert F. Kennedy (who was assassinated in June) and Eugene McCarthy together gained roughly two-thirds of the popular primary vote, but Vice President Hubert Humphrey won the backing of the unpopular president, Lyndon Johnson, and with it the nomination. Party leaders were historically happy to ignore the will of ordinary voters.

That began to change in 1970. Democrats, responding to the chaos of their 1968 convention, enacted the reforms of the McGovern-Fraser Commission, making primary and caucus elections the main method by which the nominees were chosen. Republicans soon followed suit. The changes worked: In 1968, 17 states held Democratic primaries, and 16 had Republican ones. By 2000, 40 states were contested in Democratic primaries and 43 in Republican ones (the rest held caucuses). During the epic 2008 Obama-Clinton face-off, Democratic voters alone cast 35 million primary votes, a vast increase over the 13 million cast in both parties’ primaries during the 1968 contest.

The new nominating process has empowered lower-income voters, young people, African Americans, Latinos and others who historically were prohibited from participating fully in American democracy. Although Al Gore won the popular vote yet lost in the electoral college in the 2000 general election, since 1972 neither Republicans nor Democrats have nominated a candidate who took anything but first in their primaries’ popular vote.

The process in both parties isn’t “rigged,” but it’s not purely about the popular vote, either. It offers a sensible, blended approach weighted toward voters, yet it leaves room for elected leaders, party officials and activists to have a say in the outcome. This scheme prioritizes “the will of the people” while imposing checks and balances, taking into account issues such as a potential nominee’s electability and suitability as the party standard-bearer. The system is fair-minded and responsive to voters, activists and party officials alike.

The current nominating contests drive that argument home. Set aside the hyperventilating from the Sanders and Trump camps. The indisputable fact is that Sanders, despite his recent string of victories, has won a mere 42 percent of the Democratic primary popular vote, because his biggest triumphs have tended to be in low-turnout caucus states. Clinton’s popular margin over Sanders is massive: She has won 9.4 million votes to his 7 million. If the people’s will is supposed to be paramount, then Clinton is hands-down the front-runner. Moreover, it’s hard to imagine anybody winning the Democratic nomination without at least being competitive among African American voters, a key party constituency among which Sanders has routinely lost (by 38 points in Ohio, 59 points in Florida and 64 points in North Carolina). The talk that superdelegates will overturn the people’s will at the Democratic convention in Philadelphia is a red herring. Clinton is likely to win both the popular vote and the contest for pledged delegates, making her the democratically (and fairly) elected nominee of her party.

Trump’s path has been similarly fair-minded, even if he seems not to notice. The “system” that the GOP has established is simple: To win the nomination, a candidate must amass 1,237 delegates, a majority. The party has decreed that a mere plurality isn’t enough to become the standard-bearer; Trump has won about 37 percent of the vote in the primary race thus far. The rules are in place to balance competing party interests (voters, grass-roots activists, local and state officials, members of Congress, national party leaders). They ensure that the party has reasonable backstops — that its nominee isn’t likely to become a general-election disaster, which is a legitimate concern for one of the nation’s two major parties. The GOP’s rules also pay considerable deference to states and localities, a bedrock principle of conservatism, which means that each state has different procedures for selecting delegates.

In addition, the rules determine who is eligible to vote in each state’s contests, when and how the votes will take place, how the delegates will be apportioned and whether delegates are restricted from voting a certain way in a multiple-ballot contest.

Parties are membership-based organizations, but independents sometimes get a role in determining the nominees, as some state parties permit any citizen to cast a primary ballot, regardless of her party registration. Trump and Sanders tend to perform well in these “open” contests, and it’s unsurprising that the outsider Republican front-runner and the independent, self-described socialist Democrat are the ones most critical of the nominating processes. But taken together, these layered, reasonably thoughtful rules are based on a belief that checks and balances in a party primary system guard against the prospect of, say, David Duke winning the nod. (It’s hard to see how a Duke nomination would benefit democracy.)

What’s more, the rules mean that candidates must create top-notch campaign organizations and navigate a complex series of state and national interests, which could be seen as a test of the organizational skills required to run the federal government effectively. It’s fair to ask whether, if Trump has zero interest in organizing to win support in state caucuses and conventions, he will be capable of organizing a White House staff to guide the vast federal bureaucracy.

Yes, just because this system is an improvement over the past doesn’t mean it couldn’t bear further reform. But any changes should at least start with the acknowledgement that, for both parties, there’s no such thing as a purely democratic process. We already have the electoral college, gerrymandered congressional districts, two senators apiece from sparsely populated states, the filibuster and House rules giving the majority almost complete control over the legislative agenda. Faced with a vast array of competing forces, both parties chose rules that recognize the interests of voters, activists, elected officials, states, cities and towns. The rules are not arbitrarily elitist; they’re purposeful, balancing the different demands in a racially diverse democracy of more than 300 million people spread across 50 states.

If Sanders can overtake Clinton’s lead in the popular vote and pledged delegates, then he will most likely win the backing of more superdelegates and become the Democratic nominee. If he can’t, then he has a responsibility to respect the voters’ will and the party’s democratic-minded nominating system. If Trump can prevail at the Republican convention in Cleveland, he, too, will be the duly elected nominee. If he falls short, he will have lost in a democratic contest, imperfect though it may be, that is still better than virtually all other political systems on the planet.

Twitter: @MattDallek

Read more from Outlook and follow our updates on Facebook and Twitter.