When 2009 began, the Republican Party looked like a smoking pile of rubble. The GOP had lost the presidency, and much of its outgoing president’s legacy seemed set to be reversed. Republicans had fallen into the minority in both houses of Congress. And in the states, they held less than half of governorships and only about a quarter of state legislatures.

The party has since, of course, made a remarkable comeback. But that comeback didn’t unfold entirely in 2016. The seeds for it were sown all the way back in 2010 with the first midterm elections of Barack Obama’s presidency.

That year, Republicans took back the House of Representatives, which effectively blocked Obama’s legislative agenda for the remainder of his time in office. And they made dramatic gains across the states just in time for the once-a-decade redistricting process, allowing the party to enact its policies at the state level and to give itself a built-in advantage in many House and state legislative races for the next decade.

This time around, the first Trump midterms — which will take place on November 6, 2018 — have the potential to be similarly momentous. As you can see here, Democrats are in essentially the same sorry state now that Republicans were in eight years ago:

But the midterms will offer the first nationwide referendum on Donald Trump’s presidency. The whole House of Representatives, a third of the Senate, and most governorships will be at stake, along with hundreds of state legislative seats and local offices around the country. The better Democratic candidates perform, the more strength they’ll have to block legislation or nominees they don’t like in Trump’s third and fourth years.

Furthermore, the midterm results in the states will have a huge impact on the next redistricting process, even though it doesn’t kick off until 2021. President Obama, for one, is already zeroing in on this — he’ll reportedly back a new Democratic group chaired by Eric Holder that will focus on the state legislature seats that will control the redistricting process in most states.

But while Democrats are hopeful they’ll be able to capitalize on a public backlash against Trump and see many opportunities to make gains in governors’ mansions, they’re also saddled with a hugely disadvantageous Senate map, gerrymandering that hurts the party’s chances in the House (and many state legislatures), and a voter base that’s seemed less engaged in non-presidential races and less likely to turn out in midterm years.

It’s impossible to know what American politics will look like after two years of Trump, and so it may seem absurdly early to write about the 2018 elections. But the reality is that neither party has much time to waste. These races are expensive and time-consuming, and the parties need to recruit strong candidates and get to work campaigning, organizing, and fundraising right away if they want to maximize their chances of winning.

The incumbent president’s party has historically been disadvantaged in the midterms

One starting point for understanding how midterms usually work is that it’s been tough for the president’s party to do well. Indeed, in 16 out of the 18 midterms since World War II, the incumbent president’s party has lost seats in the House of Representatives on net. (Due to partisanship and the prevalence of straight-ticket voting, Senate and governor results tend to go in the same direction, though there’s more variation because not all of those seats are up in every midterm.)

Furthermore, in those two midterms where the incumbent president’s party gained seats in the House — 1998 and 2002 — they gained a relatively small number: five and seven respectively. In contrast, the upper bound for losses in recent decades has been massive — Democrats lost 63 seats in 2010 and 54 in 1994, while Republicans lost 49 seats in 1974.

The trend is unmistakable, but the exact reasons for it aren’t entirely clear. It’s not as simple as people becoming disillusioned with the new president once he’s in office, since most presidents do go on to get reelected. Perhaps a president’s supporters naturally become more complacent about the state of things when he’s not on the ballot and certain to spend another two years in office, while his critics naturally become energized and eager to express their displeasure with the administration in whatever way they can.

In any case, the past three midterm elections — 2006, 2010, and 2014 — have all been “wave” elections in which there was a backlash against the president’s party, which should give Democrats hope. Plus, Trump won fewer votes than Hillary Clinton and is already historically unpopular for an incoming president — and once he is saddled with responsibility for governance, there’s a whole lot that could go wrong for him and drive down his popularity.

But of course there’s no guarantee that will happen. Again, the two midterm years just before those three waves — 1998 and 2002 — were essentially ties, with little net partisan change in Congress or in governors’ races. The Republican Party’s support base has increasingly relied on older voters, who are generally more likely to turn out consistently, including in midterms. And the past year should teach us the perils of underestimating Trump, since for all we know, his political strategy could prove effective.

Democrats face serious challenges in the congressional map — especially the Senate

To retake the Senate — and therefore to get veto power over all legislation and Trump’s nominees — Democrats need to pick up just three seats, on net. To retake the House, they’ll need a net gain of around 24 seats. Historically, that’s actually quite close to the average net gain of an out-party in the timespan above.

That’s where the good news for Democrats stops. Even if Trump’s popularity declines, any effort to retake Congress will be very much an uphill struggle for the opposition party. The particular batch of Senate seats up for election are not favorable for the Democrats. And the House map is bad for Democrats in general.

For the Senate, at least 33 seats will be on the ballot. But because this group of Senate seats was last up in 2012 and before that 2006 — two very strong Democratic years — this group of senators is overwhelmingly Democratic. The party will be defending a massive 25 seats, compared with just eight for Republicans.

Even more frighteningly for Democrats, 10 of those seats are in states Trump won — and five of them are in states Trump won by 18 points or more. Those five senators — Joe Manchin of West Virginia, Heidi Heitkamp of North Dakota, Joe Donnelly of Indiana, Jon Tester of Montana, and Claire McCaskill of Missouri — will start off as the most vulnerable. Most will face tough challenges from ambitious Republicans, should they even choose to run again. (Many incumbents faced with a political situation like this end up retiring.)

After them, five Democratic senators are running in seats that flipped from Obama to Trump — Sherrod Brown of Ohio, Bill Nelson of Florida, Bob Casey Jr. of Pennsylvania, Tammy Baldwin of Wisconsin, and Debbie Stabenow of Michigan. Then two more are running in states Trump came surprisingly close to winning — Amy Klobuchar of Minnesota and Angus King of Maine (who’s technically an independent). Plus, there’s Bob Menendez of New Jersey, who is scheduled to face trial on corruption charges next year.

Republicans face a much easier road in the Senate. Of their mere eight seats up, six are in deep red states. Only Dean Heller of Nevada and Jeff Flake of Arizona appear to be potentially vulnerable. (If Jeff Sessions is confirmed as attorney general, there will be a special election for his Alabama seat at some point as well, but Democrats would be hugely disadvantaged there.)

In the House, all 435 seats will be up, as they are every two years. Still, Democrats will face some serious obstacles. One is incumbency — most incumbents tend to be returned to office, and the GOP simply has more House incumbents. Another is gerrymandering — the GOP’s 2010 midterm landslide let the party draw the lines for House districts in many states, giving them a significant advantage in several key battlegrounds. Democrats have proven unable to make much headway in retaking the chamber ever since, but they’re hoping a backlash against a Trump presidency can help them overcome all these headwinds.

The 2018 midterms are also hugely important for redistricting

The stakes for the 2018 midterms extend beyond Trump — they’ll help define the battlegrounds of political combat for the next decade because of the impact they’ll have on the next round of redistricting.

The US Census is conducted every 10 years, with the next census schedule to take place in 2020. New districts for US House and state legislative races will be based on the results and take effect ahead of the 2022 elections.

States’ redistricting processes vary somewhat, and Justin Levitt of Loyola Law School has a good breakdown of how they work. But in most, the state legislature runs the process, with the governor usually getting veto power.

Last time around, that meant the GOP landslide of the 2010 midterms took place during a census year. The election installed all those new Republicans in state legislatures and governors’ mansions just in time for redistricting, giving them far greater opportunities to gerrymander.

The next redistricting won’t start until after the 2020 election. But crucially, many of the state politicians who will be in office for that redistricting will have been elected to four-year terms in 2018.

Indeed, in 36 states, the governor who will be in office for the next redistricting will be elected in 2017 or 2018. And in 31 states, half or more of state senators whose terms extend through the next redistricting will be elected in 2017 or 2018. (Most state House members, meanwhile, serve two-year terms and will be elected in 2020.)

Democrats have opportunities in the states — if they can manage to take advantage of them

The upshot is that if Democrats want to reverse GOP gerrymanders — and get the opportunity to do some gerrymandering of their own — they can’t afford to sit around and wait for 2020. They need to make big gains in state races in the midterms, as Eric Holder’s new Obama-backed National Democratic Redistricting Committee is pushing for.

As far as governors’ races go, they’ll be in a target-rich environment.

The vast majority of US governorships will be up for grabs in the next two years — two in 2017 (Virginia and New Jersey) and 36 more in 2018.

And since Republicans did so well in these races in 2010 and 2014, they’ll be on the defensive here — they currently hold 27 of those 38 seats. (Democrats hold 10, and independent Bill Walker in Alaska has the other.)

Furthermore, 15 of those GOP governors are term-limited or retiring, setting up open-seat contests that are usually easier for the out-party to win.

And 13 Republican-held seats are in states Obama won in 2012 (though Clinton won just eight of them in 2016). In states like New Jersey, Florida, Maine, Michigan, New Mexico, and Nevada in particular, Democrats could have a good chance of picking up governorships if the national mood turns against Trump and they manage to recruit strong candidates.

State legislatures, however, will be a tougher challenge. Republicans have racked up enormous advantages in most of the chambers they hold — in part due to gerrymandering, but also due to superior investment, organization, and simple attention (Democrats paid these seats little mind during the Obama years).

In swing states like Michigan, Ohio, North Carolina, and Pennsylvania, Democrats control less than one-third of state Senate seats. In Florida and Wisconsin, they’re barely above that threshold. And the party’s numbers in the House of Representatives in these states are barely better — they’ll have to do extraordinarily well to win back these chambers.

Perhaps there will be a massive public backlash against a scandal-prone, incompetent, or extreme Trump presidency that will hand Democrats a midterm victory on a silver platter. And perhaps there won’t — there’s no way to know in advance.

What is clear is that while the right agitated and protested ceaselessly against Obama’s presidency in its early years, they also organized and funded groups that invested heavily in winning the states — an investment that’s been paying dividends for the GOP for years. And now, as Democrats try to rebuild their party in the Trump era, we’ll see if they can pull off the same feat.