Amazon (NASDAQ:AMZN) and Microsoft (NASDAQ:MSFT) both recently reported blowout earnings, and both stocks are on fire lately. The giants are two of a handful of public companies with market caps over $1 trillion as of this writing.

The two are battling over market share in the incredibly fast-growing cloud space, with Microsoft in October of last year winning a lucrative contract with the U.S. Department of Defense worth up to $10 billion over 10 years. Amazon and Microsoft had beat out other competitors and were up against each other head-to-head in the final round.

Microsoft won in that instance, though Amazon is contesting the award, but let's consider which of the two is a better investment.

Nighttime city landscape with images from computer screens spread over the sky

Image source: Getty Images.

The case for Amazon

I see two main reasons to like Amazon: its success with its Prime membership service and the success of its AWS cloud products.

Amazon is growing its top line incredibly fast. Its revenue notched a compound annual growth rate of 27% from 2016 to 2019. The rapid pace would be admirable for any business, but especially so with a company the size of Amazon. Investments it has made in its fulfillment capabilities are bearing fruit as customers prefer Amazon's convenient and reliable shipping options and pay up as Prime members to get them.

Amazon is also the leader in an incredibly fast-growing public cloud market, capturing an estimated 32% of worldwide cloud infrastructure spending in 2019. Microsoft's Azure ranked No. 2 with 17%. According to IDC, worldwide spending on public cloud services is forecast to grow from $229 billion in 2019 to almost $500 billion in 2023. Amazon's fourth-quarter earnings report revealed an increase of 34% in revenue from its AWS cloud division, outpacing the growth rate in the business's other divisions. Having leadership in such a fast-growing market gives it an advantage over Microsoft.

Now that we've observed the benefits of AWS let's delve into the advantages of its Prime business.

Amazon Prime memberships fuels growth and injects cash as membership reaches over 150 million worldwide. U.S. Prime members pay $119 for the annual plan and get access to content including audiobooks, streaming video, music, and e-books, and free shipping on over 100 million items. Prime members also shop more than non-Prime members, a powerful one-two punch for Amazon.

Amazon is still growing product sales double digits. In its Q4 earnings report, net product sales rose 13% to $50.5 billion. Amazon's share of U.S. online shopping was estimated to be 38% last year, making it by far the leading online retailer. Its growing base of Prime subscribers will help it keep selling lots of things online.

The case for Microsoft

Microsoft can consistently grow revenue profitably. When Microsoft posted its second-quarter results recently, it boasted an excellent 32% net profit margin, which was up from 26% the year prior. Significantly, this is in stark contrast to Amazon, which at times shows disregard for margins, as it invests in growth. Microsoft's commitment to maintaining healthy profits while investing in growth gives it an edge over Amazon.

Microsoft stock offers a forward dividend yield of 1.2%; Amazon does not pay a dividend. Although Microsoft's dividend may seem insignificant, over the long run dividend-paying stocks outperform their non-dividend-paying counterparts. Microsoft's reliable profit margins and revenue growth make its dividend sustainable for the long term.

Microsoft's Azure cloud platform is experiencing incredible growth. Azure revenue has grown more than 50% year over year for five consecutive quarters. The product helped fuel a 38% increase in operating income for the Intelligent Cloud segment in the most recent quarter. Adding this high-growth business to its stable of legacy products and services like Windows and Microsoft Office Suite provides the company with revenue and diversification benefits.

The better investment

Choosing between these two incredible tech stocks is difficult. Amazon boasts remarkable growth, leadership in the cloud space, and over 150 million Prime members. However, Microsoft offers revenue growth along with consistent profits. It provides growth opportunities in the cloud space, combined with a steady stream of cash.

Therefore, if you must invest in only one of these companies, it should be Microsoft. Its balanced approach and healthy margins are reducing Microsoft's risk and lifting it over Amazon's incredible growth potential.