Detroit's filing of the biggest municipal bankruptcy in US history caps three decades of the city's steady decline, characterized by crime, shrinkage of auto manufacturing industry, and a population all too eager to leave for the more hospitable suburbs.

Detroit's bankruptcy is, primarily, a lesson in how cities and states cannot avoid their pension responsibilities without a backlash of biblical proportions. In 2006, Detroit, like many other cities and states, was facing a $1.5bn gap in its pension payments to its public employees. As Quartz noted:

The city converted them into debt called "certificates of participation", or COPs, which it sold through a legally separate financial vehicle at a floating interest rate. Then it entered into a swap with UBS that converted those to fixed rates. This swap became very expensive when rates dropped after the financial crisis. A very similar arrangement led to the Jefferson County bankruptcy, and a massive scandal that sent several financiers to jail.

Other municipalities – like Baltimore, Maryland and Nassau County in Long Island – have fallen foul of Wall Street financial engineering. That's not the main lesson to take from Detroit, however.

The main lesson is that many cities and states are facing a public pension crisis. Even if they don't come to so dark an end as Detroit, they are playing with fire.

Detroit is not alone, although its pension problems are particularly dire. The city's two pension funds are suing, objecting that emergency manager Kevyn Orr has no right to cut retiree benefits. The two pensions "have claims to $9.2bn in unfunded pension and retiree health care liabilities", according to the Detroit Free Press, whereas Orr claims they are underfunded by $3.5bn. The pension funds dispute his accounting.

Detroit's fight over its pension liabilities mirrors that of Stockton, California, where pension plans also did not take well to being second-class citizens in a bankruptcy. A bankruptcy is a process that allows a court to decide which creditors get paid back, and in what order.

Pension plans fear they will fall to the bottom of the pile – behind banks that lend money and hedge funds that hold city and state bonds. And they are largely correct in their fears.

What landed Detroit in trouble was its inability to manage its pensions – a phenomenon that is a national plague, among private companies as well as states. At S&P 1500 companies, an increasing percentage of pension managers are pouring money into risky investment strategies in the hopes of getting a better return on pension dollars.

In the public sector, it's much more concerning. According to Standard & Poor's, unfunded or underfunded pensions are common; the assets compared to the liabilities of the average state pension plan is roughly 72.9% as of 2011 (the most recent date for which information is available).

There are several factors for that, including market volatility as most public pensions are invested in stocks and bonds. You can't control the market. But you can, to some extent, manage a state budget, and many states are failing at that.

The nationwide unemployment crisis has reduced the total of taxes people pay, which, in turn, has meant that states and cities have less revenue to work with. Many states (and cities) have eased the pain and survived the recession by reducing the amount of money they pay into pension plans. There is a "problematic funding environment as growth in pension contributions consumes a larger part of those states' budgets," according to S&P's credit analyst credit analyst John Sugden. "Efforts to reform pension systems are far from over," he went on, "and, if anything, are intensifying as more and more policymakers look to make structural changes to their systems that will significantly lower liabilities."

One economist, Guardian columnist Dean Baker, estimated in 2011 that the shortfall in public pensions could be as huge as $1tn. A monster of this size cannot remain hidden long. It will catch up with cities and states. And since they don't have the money to pay into pensions, there is a chance that the problem will require the federal government to step in with a bailout.

The federal government is not exactly lavishly funded right now, so some in Congress have tried to head off a scenario in which the government has to bail out municipalities. In April, lawmakers introduced a bill that would force states to disclose the condition of their pension funds before they would be allowed to borrow.

That's why Detroit's bankruptcy is not just about Detroit. Many other cities and states are skirting the edge of disaster – unless they find a solution to their pension problems.