Jose Luis Coca was cooking tacos on a corner of Insurgentes, one of the main roads into central Tijuana, when the shooting began. Four carloads of gangsters, with AR15 assault rifles, opened fire on a rival gang gathered in front of his stall. Within minutes, 400 rounds had racketed the night sky, and 16 people lay dead or dying.

Mr Coca survived by lying face down on the pavement, and crossing his fingers. His taco stand still bears witness to the lucky escape, eight bullet holes in its pockmarked frame. "One missed my head by maybe 10 centimetres," he says. "It went so close I could feel it. Every day since, I thank God for protecting me."

That was in September. Since then, Mr Coca has done an awful lot of thanking God. In November, two men were murdered outside a seafood restaurant 100 yards away, this time in daylight. Last month, he saw the driver of a Ford Explorer dragged from his vehicle at the local traffic lights, frogmarched to the nearby river, and dispatched with a single shot to the back of the head.

Download the new Independent Premium app Sharing the full story, not just the headlines

Such tales have become common in Tijuana, a ramshackle border city on the front line of a bloody drug war sweeping Mexico's northern frontier. Violence between rival groups of organised criminals has been bubbling there for years, but has now reached epidemic levels. To the consternation of the world, a staggering 6,500 people were murdered in Mexico last year, including hundreds of soldiers and policemen.

Many of the dead have been decapitated, or publicly tortured. Hundreds of innocent bystanders, like Mr Coca, have been caught in the crossfire. "I've been working this spot for 20 years," he says. "Lately, I've learned not to mess with anybody. When people come here drunk, and ask for free food, I just say, 'OK, you can pay next time'. You get into an argument with these guys, they'll just kill you. This is the reality of life now: say the wrong thing to the wrong person, and you're a dead man."

The violence has left Mexico, a nation that boasts the world's twelfth largest economy, in danger of being declared a "failed state". Tourism, one of its largest industries, has collapsed. Whole regions are under the control of drug cartels, and hobbled by rampant corruption. Two months ago, the US Joint Forces Command declared that, after Pakistan, it was the world's most likely nation to suffer a "rapid and sudden collapse".

Last week, President Barack Obama had a request from the Texas Governor, Rick Perry, to station National Guard troops along the border. On Friday, the Secretary of State, Hillary Clinton, said she was planning an urgent diplomatic visit, to discuss the soaring violence with the government of President Felipe Calderon.

Barry McCaffery, a former "drug tsar" for Bill Clinton, said: "The dangerous and worsening problems... fundamentally threaten US national security. We cannot afford to have a 'narco state' as a neighbour."

Tijuana's problems stem from an accident of geography. A sprawling, seedy, and crowded city jammed up against the US border at the top of Baja Mexico, it represents prime real estate for anyone wishing to smuggle some of the 350 metric tonnes of cocaine that find their way into the United States each year. Since 2006, rival gangs have been battling for control of these drug routes. They are well-funded – the cocaine industry in the US is worth $5.5bn (£3.9bn) a year – ruthless, and care little for human life. More than 800 people were killed on the streets of Tijuana last year, from a population of 1.5 million. This gave the city a worse murder rate than Baghdad.

The killings are often sickening. A few weeks back, the decapitated heads of three policemen were left in an icebox by the side of a road. Days earlier, police near Tijuana had arrested Santiago Meza, a local drug baron's "fixer" known as El Pozolero ["The Soupmaker"]. He confessed to having dissolved more than 300 murder victims in acid over nine years.

Daily coronavirus briefing No hype, just the advice and analysis you need Enter your email address Continue Continue Please enter an email address Email address is invalid Fill out this field Email address is invalid Email already exists. Log in to update your newsletter preferences Register with your social account or click here to log in I would like to receive morning headlines Monday - Friday plus breaking news alerts by email Update newsletter preferences

"In the past, the gangs had rules," says Victor Clark Alfaro, a local human rights lawyer. "They respected families. They didn't kill children. But those rules have changed. Now they don't respect anything. They'll kill anybody, and decapitate them, or cut the body, to send a message to society."

The breakdown in law and order stems from the 1980s and 1990s, when the US launched a crackdown on Colombian drug cartels, allowing Mexican syndicates to emerge in their place. Soon these groups controlled almost nine-tenths of America's entire supply of cocaine from South America. For many years, Mexico's cartels were largely left to get on with business, on the basis that they killed only their own kind. But the arrival of multi-party democracy to in 2000 – for 70 years, Mexico had been a one-party state – led to government crackdowns on their trade. These had some success. The Arellano Felix cartel, which for years controlled a north-west portion of the country, has lost most of its leaders, including, most recently, Eduardo Arellano Felix, one of the seven brothers who founded the organisation. He was captured in October, after a shootout at a house overlooking the city, which last week was still derelict, and riddled in bullet holes.

Unfortunately, when you arrest one drug baron, you do not kill off the trade. Instead, you create a vacancy, and a turf war. Most of the recent violence across Mexico, and in Tijuana in particular, has involved remnants of the Arellano Felix cartel battling rivals from the so-called Sinaloa syndicate, and Gulf Cartel, both keen to move in on the patch.

The impact of this war is visible throughout Tijuana, where army units patrol the streets day and night, and civilians think twice about venturing out after dark. In almost every neighbourhood, gangland territories are marked by shoes dangling from electricity wires hanging across streets.

"Three shoes stands for 'El Teo', who is from the Sinaloa family," says Jorge Ramos, a security guard at a bank outside the city's notorious red-light district. "Five means 'Felix'. Seven stands for 'Sinoloa'. You learn to read the signs. Ending up on the wrong street can mean trouble."

Efforts to halt the violence are not helped by rampant police corruption. The cartels, with their 2,500 per cent profit margins, are not short of bribe cash. Forbes magazine revealed that Joaquin "El Chapo" Guzman, head of the Sinaloa cartel and Mexico's most wanted man, was worth a cool $1bn, making him 701st in its league of the world's richest men.

Local politicians describe Tijuana's police as institutionally corrupt. "I'm firing about 400 of my 1,600 police officers," the city's mayor, Jose Reyes, said in a recent documentary, Narco War Next Door. "They failed a lie-detector test in which we specifically asked if they were involved in corruption related to organised crime."

Violence is also fuelled by a flow of guns and ammunition over the border from the US, from states such as Texas, where assault weapons can be sold to anyone passing a rudimentary background check. In a desperate effort to stem the tide, one of the army bases in central Tijuana offers to exchange illegal firearms for money or food, no questions asked.

And while the US consumers created the market for the drugs that has caused this war, US politicians are also unwittingly providing many of its footsoldiers. Every day, buses arrive in Tijuana carrying hundreds of illegal immigrants, rounded up for deportation from America. Impoverished and desperate, many are immediately recruited by cartels.

"These people have nothing to lose," says Victor Clark Alfaro, who works with deportees. "They speak English, and many were in gangs in the US, so they know the business of drugs and they have contacts on the US side, so they become a cheap labour force for organised crime."

It is not as if Tijuana is exactly brimming with other opportunities. Though only 25 of the city's 800-odd murder victims last year were classed as innocent bystanders, the US State Department has advised its citizens against travelling south of the border. US Marines at Camp Pendleton, a base north of San Diego, are banned from crossing the border on leave. This has crippled the local economy, which for years relied on free-spending Americans visiting to stock up on cheap liquor and pharmaceuticals. In Rosalito Beach, a resort containing a seedy mixture of tattoo parlours, hotels, and chemists, the streets are deserted, despite the imminent "Spring Break" which normally brings tens of thousands of visitors. "This is my livelihood," says Christian Roza, owner of Dulceria Ayala, a sweet store. "It's safe in this town. Look at the place. Have you seen anyone killed here?"

The Mexican government insists that it is winning the war on drugs, and is deeply critical of what it sees as sensationalist reporting by Western media and governments. President Felipe Calderon condemned Forbes for including "El Chapo" in its rich-list. "Magazines are not only attacking and lying about the situation in Mexico, but also praising criminals," he said.

But Mr Calderon's best hope may lie in simple economics. "Wars are expensive," says Bruce Bagley, an expert on drug-trafficking from the University of Miami. "The violence has made it more costly to run drugs over the Mexican border, so more cocaine is coming through Haiti or Dominican Republic or Puerto Rico. Mexico's share of the market is down from 90 per cent to nearer 65 per cent." Dr Bagley believes the drug war has three possible outcomes. "Either one cartel emerges and takes over everything, with the government turning a form of blind eye. Or there'll be an internal agreement between cartels to stop fighting. Or the cocaine industry totally atomises with drugs entering the US from different routes."

Whatever the ending, for Mexico's tourist guides and taco-stall owners alike, it cannot come soon enough.