Shopify (SHOP 1.26%) and Veeva Systems (VEEV 0.34%) are two cloud-based companies that have made investors a lot of money. Shopify surged nearly 180% since the beginning of the year, while Veeva rallied 40%.

However, Shopify and Veeva are very different companies that serve completely different markets. Let's examine these two high-flying cloud service stocks to see which is the better buy at these elevated prices.

A graphical representation of cloud computing.

Image source: Pixabay.

What do Shopify and Veeva do?

Shopify is a one-stop shop for retailers that want to digitize their businesses. Its platform helps businesses design, set up, and run online stores. It also helps them process orders, payments, and shipments, maintain customer relationships, and leverage analytics to evaluate their overall business performance.

Veeva's platform providers customer relationship management (CRM) services for healthcare companies. Its core products include the Veeva Vault, which tracks prescribing habits, clinical trials, and industry regulations; and the Veeva Commercial Cloud, which helps drug companies maintain customer relationships.

How fast are Shopify and Veeva growing?

Demand for Shopify's services has been soaring, fueled by the decline of brick-and-mortar stores and the growth of digital channels. Even Amazon (AMZN 1.49%), which previously competed against Shopify, now integrates Shopify's platform directly into its online marketplace.

That's why Shopify's revenue rose 95% in 2015 and 90% in 2016. Wall Street anticipates 67% growth this year, which represents a slowdown but still reflects robust demand for its e-commerce services.

Veeva's top line growth has been lifted by elevated competition among drugmakers, rapidly changing industry regulations, and a constantly updated list of clinical trials. Leading drugmakers like Pfizer and Novartis pay Veeva to access that data and maintain customer relationships on its constantly updated cloud platform.

Veeva's revenue rose 31% annually in fiscal 2016 and accelerated to 33% growth in 2017. However, analysts expect that momentum to slightly wane with 24% growth this year.

Which company is more profitable?

Many cloud-based companies excel at growing revenues but struggle to generate a profit. That's mainly due to the high cost of securing new customers and supporting that growth with new services. Shopify hasn't ever reported a full-year profit, but analysts expect its losses to narrow this year before it achieves profitability in fiscal 2018.

A shopping cart icon on a smartphone.

Image source: Getty Images.

Shopify's expenses remain high due to some big investments in the expansion of its ecosystem -- which include Shopify Pay, which lets vendors store customers' payment information, a point-of-sale card reader, a wholesale channel for buyers, and new APIs that let developers integrate Shopify's platform into their apps.

Veeva has done a better job at keeping its expenses under control, and it's profitable by both GAAP and non-GAAP measures. Its non-GAAP net income earnings rose 43% last year, and analysts anticipate 38% growth this year.

Veeva has also invested in the growth of its ecosystem with new services for Veeva Vault and Cloud, but it hasn't expanded its services as aggressively as Shopify, since its big customers likely prioritize consistent performance over the introduction of new features.

Which stock is fundamentally cheaper?

Shopify doesn't have a P/E due to its lack of consistent profits, but its price-to-sales ratio of 21 is much higher than the industry average of 6 for application software makers.

Veeva trades at 72 times earnings, which seems lofty but is actually lower than the industry average of 101 for health information services providers. However, its P/S ratio of 14 is much higher than the industry average of 5 -- indicating that a lot of optimism is already baked in.

So which stock is a better buy?

I like both stocks as growth plays, but I believe that Veeva's profitability makes it a better buy than Shopify. Veeva's stock price still looks lofty relative to those profits, but it should have more downside protection than Shopify, which could quickly crumble during a market correction.