Stylish young entrepreneurs donning posh designer suits huddle around their MacBooks, sipping artisanal lattes and feverishly typing away as house music booms in the background. Dozens of hackers queue for lunch in a bustling courtyard outfitted with gourmet food trucks, pingpong tables and pop-up art installations.

This is a scene that could be easily hand-plucked out of the heart of downtown San Francisco. Yet it's taking place thousands of miles away, at the Latitude59 tech conference in the tiny Baltic nation of Estonia.

If you're like most Americans, you probably can't find Estonia on a map — but make no mistake, Estonia has found you.

Over the past two decades, this former Soviet-controlled nation — home to just 1.3 million people, or under one-sixth the size of New York City — has quietly become one of the most tech-savvy countries on earth. Estonia is the 79th smallest country in the world by population but holds the world record in startups per person. It has among the world's fastest broadband speeds. The country teaches every kid how to code. Nearly all government services are conducted online. Citizens can access their health records in the cloud and pay for parking with their mobile phones.

Talk to the average Estonians and they practically ooze entrepreneurship. Residents take pride in how they've built a collective culture of innovation; famed Silicon Valley investor Marc Andreessen recently tweeted about his love for Estonian founders, after leading a $58 million fundraising round for TransferWise, a peer-to-peer money-transfer startup started by two Estonian founders in 2011.

He's not the only one to take notice. One venture capitalist, Dave McClure, coined the Twitter hashtag #EstoniaMafia to describe the cultish startup scene.

So how is it that this unlikely country leapfrogged the rest of the world and became a technology pioneer?

Estonia's dark past: Stroll the streets of Tallinn, Estonia's capital city, today and you'll encounter tree-lined thoroughfares filled with a seemingly endless array of WiFi cafes. But it wasn't always this way.

In the 1930s, Estonia boasted nearly the same living standards and GDP per capita as Finland, its northern neighbor. Less than 10 years later, that would all be over. The Soviet annexation of Estonia in 1940 crippled the country's economy. By the time the country regained its independence in 1991, Estonia had one-ninth of Finland's GDP and four times its infant mortality rate.

But rather than hampering Estonia for good, this disparity sparked a sense of competition and a nationwide desire to reclaim the country's glory.

"When we got our independence, we didn't have anything," TransferWise head of product Martin Sokk said in an interview at the company's chic Tallinn office. "That allowed us to create something new and build our own system."

How the country turned around: In a sense, Estonia itself was a startup, and one that happened to blossom during the tech and internet boom of the 1990s. As a result, the country was never burdened by old, legacy technologies and could build up using only the internet.

Government leadership played a sizeable role. In 1994, Estonia became the first country to institute a flat-tax. Then-Prime Minister Mart Laar also championed a host of market reforms — including free trade and privatization — designed to remove red tape and simplify the process of starting a business. Today, 95% of residents declare their taxes online and can do so in typically under five minutes.

Current President Toomas Hendrik Ilves has been no less influential. Ilves, who speaks flawless English and sports a three-piece suit and bow tie, is not exactly a typical world leader. Born in 1953 to Estonian parents, Ilves grew up in New Jersey, where his passion for technology blossomed. "I was one of the very few people who were put into a math program when I was 13," Ilves said during a recent interview. "I learned to program, and I worked as a programmer in college. This is one of the reasons I was drawn to technology and its implications."

Mindaugas Kulbis/AP

Ilves is nearing the end of his second and final term, but he's been a transformational force for the country's tech sector. In 1998, he led a program to equip every classroom with computers and internet access. "I got trashed completely for several years, but my thinking was that 3-5% of the children who get to a computer — even if they are just a poor kid in the countryside — will have the innate curiosity to tear it apart," Ilves said.

Ever since, e-Estonia has blossomed. In 2000, the government declared internet access a human right. It also passed a landmark law making digital signatures legally binding and equivalent to physical signatures.

In 2002, the country issued mandatory digital identification cards, allowing citizens to sign documents using an electronic signature and access government services online. The country also instituted a cutting-edge X-Road technology platform to help organize, manage and share private and public data between government institutions. That system allowed Estonia to institute online voting in 2005, becoming the first country to ever do so.

The turning point: These innovations laid the groundwork for Estonia's first major success story: Skype.

Estonian engineers developed the code behind Skype in 2003 (and had already invented Kazaa, the file-sharing network). When the company sold to eBay in 2005 for $2.6 billion, it triggered a windfall. "Suddenly, four kids in a place that everyone said was just a backwater boondox came up with something that became a worldwide phenomenon," Ilves said. "They became filthy rich and changed the whole mindset here from "Why should I study math?" to "I too could be one of those guys."

As the Skype founders became rock stars, a new generation of young Estonians flocked to try their hand at tech. Today, high-tech industries now make up about 15% of Estonia's total GDP. There are an estimated 350 Estonian startups — one for every 3,700 citizens — including well-known companies such as Playtech, of the largest online gambling software companies, Fitsme, an online fitting room for clothing retailers, and TransferWise.

Skype's success also helped attract big money from the Silicon Valley. According to Andrus Viirg, who serves as Estonia's envoy to the Silicon Valley and the director of Enterprise Estonia, a government-funded foundation designed to support the growth of entrepreneurship, Estonian startups raised $100 million in foreign capital in 2015.

Today, Estonia's government remains focused on hyper-growth. The government recently rolled out an e-Residency program, which has attracted worldwide attention and recently landed Prime Minister Taavi Roivas on The Daily Show. The program allows anybody to become an e-citizen of Estonia, in turn giving them the ability to register a business in the country from anywhere in the world. Participants will also soon be able to open an Estonian bank account. According to Estonian government CIO Taavi Kotka, 1,000 companies have registered and 10,000 e-residents have signed up since the program began last year.

Challenges remain: Despite its success, Estonia remains one of the European Union's poorest nations, and unemployment remains an ongoing issue, although it has significantly come down from its recent high of 20.1% at a point during 2010.

There are a host of other challenges. For one, Viirg says he often faces concern from investors over Estonia's geopolitical relationship with Russia under President Vladimir Putin. "The hardest point right now is explaining the geopolitical situation — who we are, who our neighbors are, and explaining why the Ukrainian situation couldn't happen in Estonia," Viirg said.

That anxiety may seem hypothetical — but it's not. The country was hit by a massive cyberattack in 2007 — eventually attributed to Russia — which disabled the websites of government ministries, banks, media outlets and private companies. It was the first time an entire country was targeted on such a severe scale.

Still, the country survived and built up its cyber security to among the best in the world. "We survived it," said Siret Schutting, head of marketing for Cybernetica, the company powering Estonia's e-government. "We proved we have what it takes to be a cybersecurity powerhouse. Even if there is a coordinated cyber attack, we are capable of defending the system."

The country is plagued by another issue that is all too familiar to the Silicon Valley: diversity. "We are still dominantly white and male," said Sten Tamkivi, co-founder and CEO of Teleport and a former early executive at Skype. "Estonia has a lot of work to do."

The diversity issue, according to Tamkivi, has also been exacerbated by the Syrian refugee crisis, which has led to increased support for Estonia's right-wing populist political parties nationwide. "The migration crisis has created an issue where someone from a village outside of Tallinn doesn't distinguish between a terrorist, a war refugee, or top tech talent from India," Tamkivi said.

"For me, it's our biggest threat right now and has placed strain on the tech sector."

Lessons for the world: While certainly not immune to these challenges, Estonia's surprising success offers several lessons for countries like the United States.

The first, according to Ilves, is quite simple: Invest more in math and engineering. "In the United States, education has become far less demanding. People would rather study soft stuff rather than the hard stuff. But there's a correlation between quality of math education and tech success. It's never too late to learn how to code," he said.

That lesson, according to Ilves, applies just as much to policymakers themselves. "For the people who do laws and policy, very often the last time they took math was in grade school. They don't really follow these things and it is all kind of mystical to them," Ilves said.

FREDERICK FLORIN/Getty Images

What else can countries — particularly those that are not nearly as small and new — learn from Estonia's success? Whereas Silicon Valley is notorious for its strong libertarian undercurrent, Ilves says Estonia provides evidence of what happens when government and the tech sector work closely together. "Where Estonia has done much better than other countries is that policy and IT are not at opposite extremes. There is a willingness here to solve problems and approach issues in a way that is technologically friendly," Tamkivi said.

Unlike the United States, there's a constantly revolving door of top talent between entrepreneurship and government in Estonia, which has helped close the divide between the two worlds. It's not uncommon for top entrepreneurs to become civil servants, and vice versa. By contrast, the pipeline of young tech talent in the U.S. government is virtually nonexistent; the percentage of young people under 30 working in government hit an all-time low of 7% in 2013.

Estonians also demand more for their tax dollars. "The contrast between the quality of services in the private and public sector in the United States is so stark," Tamkivi said. "What puzzles me is how normal Americans consider that gap. The way Americans cave and accept that government services have to be shitty shows they've given up."

If the United States is to avoid a repeat of the healthcare.gov meltdown, Ilves says it will need to embrace a national government identification system. "There is this visceral antipathy in the United States to the idea of a government ID," he said. "It is completely anathema. But therein lies a lot of the problems with the services in the United States that Estonia doesn't have. Identification is such a crucial issue."

Could an entity as large and legacy-oriented as the United States government ever make that a reality? "The question should never be can you, it is should you," Schutting said. "You can't do everything at once, but start with a pilot with local institutions and layer on more after the fact.

"The opportunities are limitless."