Here are three trends that are often discussed in isolation:

  1. The low birth rates of advanced economies

  2. The rise of a xenophobic anti-immigration politics

  3. The fragility of the welfare state

While these subjects might seem to have nothing to do with each other, in fact they crash into each other like dominos. As rich countries have fewer babies, they need immigration to grow their prime-age workforces. But as the foreign-born share of the population rises, xenophobia often festers and threatens egalitarian policymaking.

There is no reason to think that this cause-and-effect is inevitable, but the trend is clear enough that liberal policymakers need to think hard about this doom loop and how to break it. Let’s spell it out in greater detail.

First, babies. American demographers are “freaking out as each year brings a new record low in the number of women giving birth. There are several ways to cut the fertility data—including annual births per population, or total lifetime births per woman. But every statistic tells the same story: Americans are having fewer babies than they were 50 years ago, or even 30 years ago. Japan and many European countries are dealing with their own “perfect demographic storms.”

A baby shortage sounds like an adorable misfortune of middling significance. Actually, it’s a critical problem. To expand their economies, countries need to expand their populations, particularly at a time of low productivity growth. Rich countries also need a larger and richer workforce to pay for government services to the sick, poor, and elderly. In the long term, with automation, these countries may run out of jobs. But in the short term, they are running out of people. In fact, the number of Americans between 25 and 54 years old has not grown in more than a decade.

That brings us to the second story: immigrants. As the birth rate has declined in the U.S., Canada, Western Europe, and Japan, the immigrant share of their populations has increased. This is a perfectly natural and good development. These countries have high median incomes, which are attractive to international migrants, plus their economies need new humans to sustain both GDP growth and government services.

This might sound counterintuitive to some people who’d assume that a large influx of low-skilled immigrants would be a huge drag on federal resources. In the short term, they might be. But as the children of immigrants find jobs and pay taxes, immigrant families wind up being a net contributor to the government over many decades, according to a 2016 report from the National Academy of Sciences. Beyond this economic accounting, there is a strong moral case to allow families from low-income countries move to a richer country, where they can improve their lot by an order of magnitude.

But there is a growing body of evidence that as rich majority-white countries admit more foreign-born people, far-right parties thrive by politicizing the perceived threat of the foreign-born to national culture. That concept will sound familiar to anybody who watched the 2016 U.S. presidential race, but it’s a truly global trend. A 2015 study of immigration and far-right attitudes in Austria found that the proximity of low and medium-skilled immigrants “causes Austrian voters to turn to the far right.” The effect was strongest in areas with higher unemployment, suggesting that culture and economics might reinforce each other in this equation. Last week, the far-right Austrian party triumphed in the nation’s election.

This is where the story finally connects with welfare and the future of liberalism. Rich countries tend to redistribute wealth from the rich few to the less-rich multitude. But when that multitude suddenly includes minorities who are seen as outsiders, the white majority can turn resentful and take back their egalitarian promises. Take, for example, the Twin Cities of Minnesota. They were once revered for their liberal local policies—like corporate-tax redistribution from rich areas to poor neighborhoods and low-income housing construction near business districts. But since the 1980s, as the metro area attracted more nonwhite immigrants, the metro has become deeply segregated by income and race and affordable-housing construction has backtracked. Or take Finland, that renowned “Santa Claus State” of cradle-to-grave social services, where the welfare state is being “systematically dismantled.” The far right has emerged in the last few decades, just as foreign-born population has suddenly grown.

The modern liberal vision of the U.S. is a pluralistic social democracy—the dream of a nation that uniquely promotes both diversity and equality. The marriage of those twin virtues is, perhaps, the singular American experiment—even if, outside of California, Canada seems to be doing a much better job with the execution. But an unavoidable lesson of the last few years, from both inside and outside the U.S., is that cultural heterogeneity and egalitarianism often cut against each other. Pluralist social democracy is stuck in a finger trap of math and bigotry, where to pull on one end (support for diversity) seems to naturally strain the other (support for equality).

The future of the U.S. economy depends on population growth. The future of U.S. population growth depends on immigration. But, as in so much of the world, immigration can trigger bigotry and backlash. The liberal cause requires  Americans learning to break the catch-22 of diversity and equality. If multicultural egalitarianism is the future of liberal politics, the road to the future will be bumpy.