The two companies in today's matchup share the same roots. Peter Gassner, founder and CEO of Veeva Systems (VEEV 1.02%), was an executive at Salesforce (CRM 1.05%) when he realized an opportunity: Drug companies had specific cloud needs that Salesforce couldn't meet.

Taking that seed of an idea, he founded Veeva in 2007 and took it public in 2013. Since hitting all-time lows shortly thereafter, Veeva has rallied to return 350% for shareholders. Over the same time frame, Salesforce -- which actually hosts some of Veeva's cloud applications -- has lagged, returning a still-very-impressive 180%.

Businessman's hand pushing a cloud icon button

Image source: Getty Images.

Is this a case of the student (Veeva) outshining the mentor (Salesforce) over the long run? Or are investors wise to pick the original giant in software as a service (SaaS)? We'll try to decide which by evaluating these two stocks on three different factors. Here's how they stack up:

Financial fortitude

When it comes to financial fortitude, what we really want to know is what would happen in the event of a black swan: an unpredictable event that has huge consequences for (in this case) the economy. 

If a company has lots of cash on hand, it can actually benefit by putting it to work by taking advantage of depressed prices. If, on the other hand, a company has lots of debt and can't afford blips in free cash flow, it could be forced to issue more stock, take on more debt, or worse.

Keeping in mind that Salesforce is valued at over eight times the size of Veeva, here's how the two stack up:

Company Cash Debt Free Cash Flow
Veeva $1.0 billion $0 $266 million
Salesforce $8.3 billion $3.5 billion $2.5 billion

Data source: Yahoo! Finance, Veeva IR. Cash includes short- and long-term investments. Free cash flow presented on trailing-12-month basis.

Both companies are in a great position. Veeva has absolutely no long-term debt, and its free cash flow has grown by 22% over the first six months of 2018. While Salesforce has taken on some debt, its net cash position still sits at just under $5 billion. And you can't ignore the incredibly strong free cash flow the company is bringing in.

Taken together, I'd say that both of these companies are poised to grow stronger -- over the long run -- in the face of an economic crisis. They could do this by buying back their own shares on the cheap, acquiring start-ups for a discount, or simply gaining market share by undercutting the competition on price.

Winner = Tie

Valuation

It's never easy to value a company. No one metric can tell you if a stock is cheap or expensive, and comparing across industries makes the task doubly hard. Luckily for us, these two have very similar business models that allow us to see more clearly how they're valued, relative to each other.

Company P/E P/FCF P/S PEG Ratio
Veeva 75 48 17.0 3.7
Salesforce 81 44 9.8 2.3

Data source: Yahoo! Finance, Veeva IR. P/E calculated using non-GAAP earnings when applicable.

This is a tough one, as both companies are expensive by traditional metrics. The companies have almost the same P/E and free cash flow ratios -- even though Salesforce is over eight times the size of Veeva.

What really tips the scales here, however, is the fact that Salesforce's PEG ratio -- which takes growth rates into consideration -- is over 35% lower than Veeva's. I would never call either one of these stocks cheap, but Salesforce has the more favorable valuation.

Winner = Salesforce

Sustainable competitive advantage

Finally, we have what I consider to be the most important factor: a company's moat -- or sustainable competitive advantage.

Both Salesforce and Veeva are SaaS companies. As such, their key competitive advantage lies in high switching costs. When Veeva signs on pharmaceutical companies as customers -- either through its older, legacy customer-relationship-management solutions or its newer, fast-growing Vault applications -- those customers are likely there for a long time. All of their mission-critical data is stored and organized on Veeva's servers. Not only would it be prohibitively expensive to transition to a new provider, but said companies also would have to retrain entire workforces on a new interface, and risk losing that data in the process. 

That helps explain why Veeva's revenue retention rate was 122% last year. Not only did existing customers stay with Veeva, they also added more tools that the company is offering.

Salesforce benefits from the same dynamics as Veeva. With its sales, service, marketing, and commerce cloud offerings, Salesforce has become the go-to provider for mass-market cloud needs.

But in the past, retention has been a concern: Its dollar attrition rate (a measure of how many subscription dollars from existing customers were lost from one year's existing customers to the next year) was in the high teens in 2011. Since then, it has come down to just below 10%. 

Perhaps it's unfair to penalize Salesforce for this figure. It is focused on companies of all sizes, in all industries, where customers can be more fickle and aren't as locked in by high switching costs. Additionally, Salesforce's newer offerings probably have higher attrition rates as customers kick the tires on the service.

That said, while Salesforce's switching costs might be understandably lower than Veeva's, that's the whole point: Veeva customers are in an industry where they simply cannot afford to leave the company. That's enough to give Veeva the edge here.

Winner = Veeva

And the winner is...

Both companies have rock-solid balance sheets, Salesforce has the slightly better valuation, and Veeva's moat is wider by a hair. When such a tie occurs, I always declare the company with stronger competitive advantages as the winner. In this case -- thanks to its superior revenue retention -- it's Veeva.

Both stocks are expensive by traditional metrics, but both have a lot going for them as well. If forced to choose, my money is on Veeva to outperform over the next five years.