Former President Barack Obama issued a warning to Democratic lawmakers to avoid a "circular firing squad" within the party that would devoid policy progress, particularly ahead of the 2020 presidential election.

Speaking in Berlin during an Obama Foundation town hall, the former commander-in-chief said he worried about progressive lawmakers falling victim to "rigidity" within Washington.

"One of the things I do worry about sometimes among progressives in the United States, maybe it's true here as well, is a certain kind of rigidity where we say, 'Uh, I'm sorry, this is how it's going to be,' and then we start sometimes creating what's called a 'circular firing squad,' where you start shooting at your allies because one of them has strayed from purity on the issues," Obama said. "When that happens, typically the overall effort and movement weakens."

Pointing to examples like his passing of the Affordable Care Act and the Paris Climate Agreement, Obama also emphasized the importance of compromise in making progress within a democracy among citizens and lawmakers who don't agree with a given core philosophy or policy.

"You have to recognize that the way we structure democracy requires you to take into account people who don't agree with you," Obama said. "That by definition means you're not going to get 100 percent of what you want,"

Warning of external threats to democracy, Obama said the resurgence of nationalism in America "divides us into us and them" and breeds a hostile, unproductive environment.

The former president's comments come amid a crowded Democratic field with nearly 20 hopefuls in the running for the 2020 election.