Suddenly, China is a mess.

The Shanghai Stock Exchange Index is down 14% this year, and down by more than a third over the last three years. It trades lower today than it did in early 2009, when the global economy was nearing collapse.

Manufacturing, long China's engine of growth, is now contracting. Imports are down. Economists around the world are cutting their forecasts of the country's economic growth.

China's banking system is straining, too. Interest rates tied to interbank lending surged to more than 20% last week as a credit crunch emerges after years of binging on debt.

How will this end?

We really have no idea. China's economy is heavily controlled by its government, and -- importantly -- much of its banking system is state-owned. Financial crises are usually triggered by a lack of confidence among investors. But if your main investor is a government agency indifferent to losses, the playbook is very different.

I'll make a long-term guess, though. Twenty years from now, we will look back on China similarly to how we now look back on the Japanese economy of 20 years ago.

The two stories have an uncanny similarity: Investors holding an unshakable amount of optimism while ignoring massive demographic problems.

Japan was the envy of the economic world 20 years ago. Economists gushed. Businesses were wooed. Even author Michael Crichton wrote in 1992 that, "Sooner or later, Americans must come to grips with the fact that Japan has become the leading industrial nation in the world."

It didn't turn out that way. Why? Mostly because the Japanese population got too darn old. It's nearly impossible to grown an economy when retirees grow faster than the workforce, which is what happened in Japan. Most of those who became dewy-eyed at Japan's prospects 20 years ago missed this completely. The result has been two decades of stagnation.

China could suffer a similar fate.

China has a lot going for it: More than a billion people, cheap labor, efficient manufacturing, and a culture of ambition.

But because of its one-child policy, the country is getting old. Really old. Its working-age population went into decline last year, just when its economy started slowing down.

According to Census Bureau data, working-age Chinese (those age 15 to 64) currently make up 74% of the country's total population. By 2030, that figure will drop to 68%, and all the way down to 60% by 2050. America's working-age population is set to decline, too, but not nearly as much -- from 66% today 61% by 2050.

China's population is so large that this rapid decline in its working-age population adds up to literally hundreds of millions of people: 

Source: Bureau of Labor Statistics, author's calculations. 

This is virtually the same trend that pushed Japan's growth prospects off the rails for the last 20 years.

Predicting what any economy will do is a lost cause. No one can do it with any accuracy. But I'll try. I like to think that China's story will play out like this: Growth will slow, a little at first and then dramatically. Millions of investors will lose, and legions of economists will be humbled. The culprit will be demographics, and like Japan 20 years ago, we'll look back and wonder why it wasn't so obvious.

I'm a fan of investor Marty Whitman's motto that, "Rarely do more than three or four variables really count. Everything else is noise." Over the long term, the most important number China needs to worry about is its plunging population of working-age citizens. Everything else might be noise. 

Check back every Tuesday and Friday for Morgan Housel's columns on finance and economics.