Twenty years ago, there was no such things as software as a service (SaaS). If you wanted to run software on your computer, you had to go out, pay nosebleed prices for a CD, and download the program onto your computer.

But with the advent of the internet and cloud connectivity, that all changed. Now, you can simply pay a monthly subscription fee and run software on the cloud that's automatically updated. One of the biggest SaaS winners has been Salesforce (NYSE:CRM), which provides cloud software for thousands of companies worldwide.

A person drawing a diagram of how SaaS works

Image source: Getty Images.

An upstart making inroads in the same industry -- Veeva Systems Inc (NYSE:VEEV) -- was actually born out of Salesforce. Veeva founder and current CEO Peter Gassner was an executive at Salesforce when he realized pharmaceutical companies had very specific SaaS needs -- due to regulations -- that the company couldn't meet. He decided to strike out on his own with Veeva to meet these needs.

So which is the better stock to buy today? There's no way to answer that question with 100% certainty. But there are three key lenses through which we can view the question. Here's how they stack up.

Sustainable competitive advantages

Nothing should matter more to long-term investors than the sustainable competitive advantages -- otherwise known as a "moat" -- of the underlying businesses they are investing in. At its core, a moat is what separates a company from the competition, keeping customers coming back month after month, while keeping the competition at bay for decades.

Both Salesforce and Veeva have the same key moat: high switching costs. Because companies spend time storing information on, training employees in, and getting used to a simple software interface, they are loath to leave their SaaS providers.

For Salesforce, gobs of customer data is stored on the company's servers; with its Veeva Vault product, Veeva is keeping the most sensitive information drug companies have safe and accessible. In both cases, switching all of those operations over to another provider would not only be expensive, but would entail retraining entire workforces and potentially losing mission critical data.

It would be impossible to tease apart which company's moat is higher. Salesforce might have a narrower moat, but its breadth of companies served gives it an edge in terms of data for what companies want in their next generation applications. Veeva might not have the same data trove, but the information being stored in Vault is valuable enough to give it a wide moat as well.

Winner = Tie

Financial fortitude

Depending on your style of investing, shareholders normally like to see two things happening with excess cash: reinvesting it in growth opportunities or returning it via dividends and share buybacks.

But there's something to be said for keeping a boring old pile of cash on hand. That's because every company, at one point or another, is going to face difficult economic times. Those that enter such times with lots of cash have options that can actually make them stronger as a result of a crisis: buying back shares at a discount, acquiring distressed rivals, or simply outspending the competition to gain market share.

Those that have lots of debt are in the opposite boat and normally suffer a deathblow for such dire times. 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

Net Income

Free Cash Flow

Veeva

$725 million

$0

$117 million

$212 million

Salesforce

$4.2 billion

$0.7 billion

($80 million)

$1.85 billion

Data source: Yahoo! Finance. Cash includes long- and short-term investments. Net income and free cash flow presented on trailing 12-month basis.

Both of these companies have very strong balance sheets. Veeva has no debt to speak of and healthy free cash flow, while Salesforce has a net cash position of $3.5 billion. And while its net income may look alarming, free cash flow is the real metric to watch. It is very healthy there.

All things considered, there's again no discernible difference between the two.

Winner = Tie

Valuation

Finally, we have the murky science of trying to determine how expensive each stock is. While there's no tried-and-true way to nail down an exact number, there are a few data points I like to consult to get a feel for valuation.

Company

P/E

P/FCF

PEG Ratio

Veeva

63

37

3.0

Salesforce

85

37

2.5

Data source: Yahoo! Finance, E*Trade. EPS used is from non-GAAP earnings.

Once again, we have a very tight battle. They are both -- without question -- expensive stocks based on traditional metrics. While Veeva is slightly cheaper on an earnings basis, Salesforce appears cheaper when considering future growth potential (PEG Ratio) -- and they are even when it comes to free cash flow.

Winner = Tie

My winner is...

There you have it: Both companies have powerful moats, solid balance sheets, and expensive price tags. Normally during a tie, I give the nod to the company with the wider moat. Since both tied on that criteria, my next tiebreaker is to go with where my own skin is in the game. I don't own shares of Salesforce, while Veeva makes up just over 3% of my real-life holdings. Therefore, the nod goes to Veeva in this very tight battle.

Brian Stoffel owns shares of Veeva Systems. The Motley Fool owns shares of and recommends Veeva Systems. The Motley Fool recommends Salesforce.com. The Motley Fool has a disclosure policy.