When it comes to ensuring the security of their regime, China's Communist Party rulers don't skimp.
The extent of that lavish spending was put on display when the boldest street protests in decades broke out in Beijing and other cities, driven by anger over rigid and seemingly unending restrictions to combat Covid-19.
The government has been preparing for such challenges for decades, installing the machinery needed to quash large-scale upheavals.
After an initially muted response, with security personnel using pepper spray and tear gas, police and paramilitary troops flooded city streets with jeeps, vans and armored cars in a massive show of force.
The officers fanned out, checking IDs and searching cellphones for photos, messages or banned apps that might show involvement in or even just sympathy for the protests.
An unknown number of people were detained and it's unclear if any will face charges. Most protesters focused their anger on the "zero-Covid" policy that seeks to eradicate the virus through sweeping lockdowns, travel restrictions and relentless testing. But some called for the party and its leader Xi Jinping to step down, speech the party considers subversive and punishable by years in prison.
While much smaller in scale, the protests were the most significant since the 1989 student-led pro-democracy movement centered on Beijing's Tiananmen Square that the regime still views as its greatest existential crisis. With leaders and protesters at an impasse, the People's Liberation Army crushed the demonstrations with tanks and troops, killing hundreds, possibly thousands.
After the Tiananmen crackdown, the party invested in the means to deal with unrest without resorting immediately to using deadly force.
During a wave of dissent by unemployed workers in the late 1990s and early 2000s, the authorities tested that approach, focusing on preventing organizers in different cities from linking up and arresting the leaders while letting rank-and-file protesters go largely untouched.
At times, they've been caught by surprise. In 1999, members of the Falun Gong meditation sect, whose membership came to rival the party's in size, surrounded the leadership compound in Beijing in a show of defiance that then-leader Jiang Zemin took as a personal affront.
A harsh crackdown followed. Leaders were given heavy prison sentences and members were subject to harassment and sometimes sent to re-education centers.
The government responded with overwhelming force in 2008, when anti-government riots broke out in Tibet's capital Lhasa and unrest swept through Tibetan regions in western China, authorities responded with overwhelming force.
The next year, a police crackdown on protests by members of the Uyghur Muslim minority in the capital of the northwestern Xinjiang region, Urumqi, led to bloody clashes in which at least 197 were killed, mostly Han Chinese civilians.
In both cases, forces fired into crowds, searched door-to-door and seized an unknown number of suspects who were either sentenced to heavy terms or simply not heard from again. Millions of people were interned in camps, placed under surveillance and forbidden from traveling.
China has been able to muster such resources thanks to a massive internal security budget that reportedly has tripled over the past decade, surpassing that for national defense. Xinjiang alone saw a ten-fold increase in domestic security spending during the early 2000s, according to Western estimates.
The published figure for internal security exceeded the defense budget for the first time in 2010. By 2013, China stopped providing a breakdown. The US think tank Jamestown Foundation estimated that internal security spending had already reached 113% of defense spending by 2016. Annual increases were about double those for national defense in percentage terms and both grew much faster than the economy.
There's a less visible but equally intimidating, sprawling system in place to monitor online content for anti-government messages, unapproved news and images. Government censors work furiously to erase such items, while propaganda teams flood the net with pro-party messages.
Behind the repression is a legal system tailor-made to serve the one-party state. China is a nation ruled by law rather than governed by the rule of law. Laws are sufficiently malleable to put anyone targeted by the authorities behind bars on any number of vague charges.
Those range from simply "spreading rumors online," tracked through postings on social media, to the all-encompassing "picking quarrels and provoking trouble," punishable by up to five years in prison.
Charges of "subverting state power" or "incitement to subvert state power" are often used, requiring little proof other than evidence the accused expressed a critical attitude toward the party-state. Those accused are usually denied the right to hire their own lawyers. Cases can take years to come to trial and almost always result in convictions.
In a further disincentive to rebel, people released from prison often face years of monitoring and harassment that can ruin careers and destroy families.
The massive spending and sprawling internal security network leaves China well prepared to crackdown on dissent. It also suggests "China's internal situation is far less stable than the leadership would like the world to believe," China politics expert Dean Cheng of the Heritage Foundation wrote on the Washington, DC-based conservative think tank's website.
It's unclear how sustainable it is, he said. "This could have the effect of either changing Chinese priorities or creating greater tensions among them."