Putting money behind healthcare companies has been lucrative for long-term investors. When those healthcare companies focus on software as a service (SaaS), it's been even more lucrative. This lean business model is capital-light and builds a moat around itself via high switching costs and network effects.

Case in point: the two companies we're investigating today --the pharmaceutical industry's preferred cloud provider Veeva Systems (NYSE:VEEV), and Cerner (NASDAQ:CERN), which specializes in electronic health records and IT. Both handily thumped the market since going public, but which is the better stock to buy today? 

A businessman with his back turned stands between two identical closed white doors.

Image source: Getty Images.

Financial fortitude

When I examine financial fortitude, I have one thing in mind: How will the company be affected by doom, whether it be a broader financial downturn or a problem specific to the company? Fragile organizations with loads of debt become weaker as management is faced with decisions about limiting scope, cutting costs, and exhausting every available resource to stay afloat.

But bad times can mean that companies with sizable cash piles grow even stronger -- plucking up competitors at cheap valuations, buying back their own stock at a discount, or simply grabbing market share by lowering prices.

Keeping in mind Cerner is about 17% bigger than Veeva by market cap, here's how the two companies stack up:

Company Cash Debt Free Cash Flow
Veeva $1.050 billion $0 $273 million
Cerner $1.150 billion $439 million $990 million

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

Let's make one thing clear: Both of these companies have very solid balance sheets. But Veeva has an edge. Yes, Cerner has stronger free cash flow, but it also has a debt load that could limit its ability to benefit from a downturn. There's nothing inherently wrong with that debt, which came from acquiring Siemens Health Services a few years back.

Veeva looks better suited to benefit from a downturn in the long run, with no debt, a growing cash pile, and free cash flow that could easily accelerate if the company wanted to take its foot off the R&D spending pedal.

Winner = Veeva Systems

Valuation

Next, we can look at each company's valuation. This is part art, part science, and I consult several different metrics to build a holistic picture of how relatively "cheap" or "expensive" these stocks are:

Company P/E P/FCF P/S PEG Ratio (Price/Earnings to Growth)
Veeva 78 55 18.5 2.6
Cerner 26 18 3.4 2.7

Data sources: Yahoo! Finance, E*Trade. P/E = price to earnings; P/FCF = price to free cash flow; P/S = price to sales; PEG = price/earnings to growth. P/E is based on non-GAAP (generally accepted accounting principles) earnings when applicable.

The winner here is clear: Cerner is either as cheap as, or cheaper than, Veeva on virtually every metric. This makes sense because Veeva has been growing much faster than Cerner and investors have driven the price of shares up.

But with that excellent performance comes higher expectations, and investors buying into Veeva today will pay a higher price because of those expectations. That makes Cerner appear to be the cheaper stock right now.

Winner = Cerner

Sustainable competitive advantages

Finally, we have what I consider to be the most important aspect to evaluate: the durability of a company's competitive advantages, referred to as a company's "moat."

Veeva benefits from two huge moats, the strongest of which is high switching costs. Veeva has two broad product lines: the commercial cloud, and Veeva Vault. The former helps drug companies track their sales and use its customer relationship management (CRM) data. The latter is the real driver of growth.

Veeva Vault has a dizzying array of products that run the gamut from development to commercialization. Its services help drug companies bring a drug from the idea stage, through clinical trials, gain approval by the Food and Drug Administration, and enter the market. Once a company starts storing all of this data on Veeva's servers, it faces enormous switching costs -- including financial setbacks, lost data, and  having to retrain staff on a new interface. This keeps customers locked into Veeva's ecosystem for the long haul, resulting in a revenue retention rate of over 120% for the last three years. In other words, existing customers not only stick with Veeva, but they also add more solutions over time.

Importantly, Veeva also benefits from the network effect: Each additional customer makes the service as a whole stronger because Veeva  collects data on the more than 400 life-sciences companies on its roster. It can use that data to offer new solutions that aim to solve problems its customers face -- solutions the competition couldn't dream up without similar data.

Cerner, on the other hand, also benefits from high switching costs. Once hospitals and healthcare centers start tracking patients' health records on its Millennium platform, they are loath to switch -- for many of the same reasons as above.

Two key problems give Veeva the edge here. First and foremost, Cerner has the largest market share of electronic health records systems, at 17.3% -- but there are huge rivals on its heels. Cerner is facing new competition from Epic Systems, General Electric, and Allscripts. Veeva's competition in its niche is nowhere near as fierce.

Lastly, Cerner doesn't provide a breakout of revenue retention, which is a key metric for determining the company's moat. I'm giving my nod to Veeva here.

Winner = Veeva Systems

And the winner is...

So there you have it: In a very close contest in terms of financial fortitude and competitive advantages, Veeva comes out ahead. The company does have an expensive stock price, but its moat and money position helped it win this battle.

I ran these companies through the gauntlet two years ago, and the result was the same. The results since 2017: Veeva has more than doubled, while Cerner's stock is unchanged. I can't promise similar results moving forward, but my own skin is in the game, as Veeva accounts for almost 6% of my family's real-life holdings.

If you're looking for a healthcare SaaS stock to invest in today, I suggest starting by doing your own due diligence on Veeva.

Check out the latest Veeva Systems and Cerner earnings call transcripts.