In 2009, as the economy of Silicon Valley started to recover from the financial crisis, Bismarck Lepe, a tech entrepreneur with a Stanford pedigree and a few years working at Google under his belt, began looking around the world for cities to put his new business, Ooyala, which provides online video solutions for business.

He knew that the venture capital companies would be ready to open the tap again after the economic slowdown. He also believed that Ooyala was ripe for a big expansion. But Silicon Valley was simply too expensive to try to hire a full staff there.

He was more than a little surprised when the colleague he had asked to assess options around the world came back with the suggestion of Mexico’s second largest city, Guadalajara. “I was originally a little hesitant,” admits Lepe, “given that my parents had left Mexico.”

In fact, Lepe’s parents had grown up in a small town not far from Guadalajara and had left the country before he was born to try their luck as farmworkers in the United States. Lepe remembered traveling back and forth to Mexico as a young child, before his parents finally settled down permanently in California, but he had never seen Mexico as a land of opportunity, much less a place to invest.

Even for most Mexicans, Guadalajara was familiar as the source of tequila and mariachi bands, not technology. Its image was stodgy and traditional, not cutting-edge.

His colleague insisted, though, telling him that Guadalajara had a strong talent pool of young programmers and engineers. Its technology ecosystem was not as mature as those of other cities around the world—including some of those in India and Vietnam—but it was developing quickly.

The tech rise of Guadalajara had taken decades to incubate. Starting in the 1960s and continuing through the 1980s, a number of foreign companies—including Kodak, Motorola, IBM, Hewlett-Packard, and Siemens—placed some of their manufacturing operations in Guadalajara. This was all about finding cheap labor for manufacturing, and Guadalajara developed a cluster of tech companies that made semi-conductors, printers, and photo equipment, among other basic components of the tech industry. “All the directors of the plants were American,” recalls Jaime Reyes, who joined HP’s Guadalajara operation in the 1980s.

By the 1990s, Reyes says, the management began to change, and he himself became HP’s first Mexican manager in 1994. By the end of the decade, most of the managers were Mexican, and there were Mexican engineers, programmers, and designers working at the plants, even though they still mostly specialized in basic tech manufacturing. Over this period, corporations worked closely with local universities to expand their tech-related courses, and the collaboration paid off by generating local talent. It looked like a highly successful model through which Guadalajara would eventually be able to move up the value chain.

Then it all came crashing down.

China’s entry into the World Trade Organization at the end of 2001 devastated Guadalajara’s tech industry. During the 2000s, many factory and engineering jobs moved to Asia, which suddenly boasted lower tariffs to go along with even lower wages than the ones in Guadalajara. The tech industry could have vanished.

But it didn’t. Instead of folding, Guadalajara reinvented itself as a major center for research and development, programming, design, and other high-skilled tech occupations, building on the foundation that had been laid years earlier. Reyes remembers the moment in the 2000s when HP’s Guadalajara operation produced the first printer designed entirely in the company’s Guadalajara offices. “We inverted the model to become the designers—and Taiwan the manufacturer,” he recalls.

Today Oracle, Intel, HP, and IBM all have major R&D and programming facilities in Guadalajara. Amazon also recently set up its own R&D facility there, and Continental Tires, a German company, produces around 20 patents a year from its local research facility. There is still some low-wage component manufacturing and assembly, but the city is now known primarily for its engineering talent and creativity.

Bismarck Lepe eventually came around to the idea that Guadalajara could be the right place to base most of Ooyala’s operations. While he was relocating to Guadalajara, he met Adal Lopez, a young, aspiring entrepreneur in the city, and he asked him to come work for him for a couple of years to lead Ooyala’s Mexican operations. Adal López really wanted to start his own company, but Lepe convinced him that it was worth his while to learn the ropes in a more established startup.

Lepe’s bet on Guadalajara—and López’s management—paid off. The company became immensely successful, and Lepe eventually sold it in 2014 to the Australian telecom giant Telstra for $410 million. The buy-out came about in large part because of the strength of Ooyala’s Guadalajara operations.

By the time of the sale, Adal López had already gone on to start his own company with support from Lepe and other Silicon Valley investors.

By 2015, Bismarck Lepe was back in Guadalajara with his latest startup, Wizeline, a business solutions company that specializes in integrating databases. Today Wizeline has 300 employees in Guadalajara with plans to expand to 1,200 by the end of the year. Meanwhile, the San Francisco head office remains lean with 25 to 30 staffers.

Lepe has become an evangelist for the benefits that Guadalajara offers for America’s tech industry. “You’re starting to get the second or third generation of technologists who have experience build[ing] scalable products,” he says. “And it’s not only the talented people that are there, but the ones we can attract to live there.” Wizeline now has employees from Egypt, France, Ecuador, Colombia, China, New Zealand, and, of course, the United States working at its Guadalajara offices. It’s easy to get them work visas, something that is becoming harder north of the border. And they love the quality of life in a city that is far cheaper than Silicon Valley but still has great cultural and recreational options.

Lepe is so convinced by Guadalajara that he started a nonprofit, Startup GDL, to promote the city as a tech hub to other Silicon Valley startups. Startup GDL currently has a long pipeline of U.S.-based small and medium-sized tech companies looking at putting part or all of their operations in Guadalajara.

But Guadalajara’s future may not lie only in attracting Silicon Valley companies but also in creating its own. Adal López, who ran Ooyala’s operations in Guadalajara, now runs Kueski, his own financial technology startup that provides small online loans—an alternative to both banks and loan sharks. In a country where banks cater mostly to the wealthy and the largest businesses, Kueski fills a niche left unserved by banks by providing fast loans to small businesspeople and the growing middle class. He has found a formula that may well work across many other emerging economies around the world that have similar problems with financial penetration.

Guadalajara is now full of small and medium-sized startups trying to emulate what Silicon Valley innovators once did to build an ecosystem of successful companies and venture capitalists. Among the most consolidated startups, in addition to López’s Kueski, are Sunu, which makes wristbands for the visually impaired, allowing them to gauge the distance of nearby objects, and Unima. Funded by both private investment and the Gates Foundation, Unima’s technology—designed to do medical testing in remote areas that lack doctors—may one day find its way not only into parts of Mexico, but also to Central America, Africa, and Southeast Asia.

When you visit, Guadalajara still has the feel of an overgrown provincial town, where you can wander through cobblestone streets past colonial churches on a quiet weekend afternoon. The city—like all of Mexico—remains firmly anchored in its past, at the same time it’s starting to build a new vision of its future. Sometimes it feels conservative and traditional, and at other times, innovative and entrepreneurial, a quirky combination that highlights the underlying tensions as Mexico moves from an inward-looking country to one that is global and outward-focused. And the modern, dynamic economy built on technology innovation still co-exists with massive inequality, pervasive graft, and enduring poverty in many parts of the country—and in Guadalajara, too.

But things are changing. In perhaps one of the signs of the times, Guadalajara three years ago elected a former journalist as the city’s first independent mayor, defeating the traditional political parties along the way, as well as a 26-year-old independent congressman, who mounted his campaign largely through social media. On July 1 this year, if polls are right, the mayor will likely be elected as the state’s governor, and the congressman will become one of its senators, both signs of the willingness to try new paths in Guadalajara and its surrounding area.

Bismarck Lepe has no illusions that everything in Guadalajara is perfect. He knows that corruption and the lack of upward mobility, some of the issues that drove his family to leave, are still a major problem there and throughout Mexico. But Mexico offers more spaces where creativity and innovation can thrive, and he’s willing to bet on these, especially in Guadalajara. “This is definitely not my parents’ Mexico,” he says.