In December, Lars Dalgaard sold his company, SuccessFactors, to German software giant SAP for $3.4 billion.

But if he hadn't taken a drive through central California in 2008, the story would have had a very different outcome.

Dalgaard started SuccessFactors in the darkest days after the dot-com bust in 2001, so he understood that good times don't last forever.

But in early 2008, the company was booming, growing around 100% per year. Despite loud rumblings about big problems in the housing market, most people in Silicon Valley were oblivious to what was about to happen.

When Dalgaard voiced his concerns, one person told him he was nuts -- just look at all the action at the mall in Palo Alto!

But Palo Alto is a rich suburb of San Francisco, home to Stanford, Facebook (at the time), and VC firms. It's not like middle America.

So Dalgaard decided to drive to ground zero of the recent housing boom, about 100 miles east of San Francisco. Developers had put up huge tracts in cities like Manteca, and Dalgaard wanted to see them for himself.

He found a wasteland.

He asked one salesperson at a development office "where is everybody?" and she told him she hadn't seen a potential buyer come through the door for two weeks.

He extended his trip and drove throughout California, looking at acres of unsold and deserted homes. "If you've ever been to 8-Mile in Detroit, that's what some of these places looked like," he said.

He was so shocked by what he saw, he became convinced the economy was about to take a big fall.

Then he made a hard call. He came home and personally fired 25% of his staff, despite the fact that SuccessFactors was still doing well.

He now believes that if he hadn't made those cuts, the company wouldn't have survived. When the market collapsed in late 2008, sales dropped more than twice as much as he and his finance people had predicted. Then, they dropped even further.

Sales picked back up with the economic recovery, and SuccessFactors ended up hiring back more people than it laid off.

Eventually the company's track record -- it had 15 million paying seats, which is more than any other cloud-based enterprise software provider -- started to draw attention from potential buyers.

In December, SAP picked it up for $3.4 billion, and Dalgaard will become an executive board member at the German software giant.

It's a happy ending -- or rather, the start of a happy new chapter -- but it wouldn't have happened at all of Dalgaard hadn't taken a trip outside the Silicon Valley bubble.