Forget e-commerce or operating systems. When it comes to the rivalry between Amazon (NASDAQ:AMZN) and Microsoft (NASDAQ:MSFT), it's all about cloud computing. 

Amazon is the leader in cloud computing with its Amazon Web Services (AWS), but Microsoft is chipping away at its dominance. That was recently on display when Microsoft was awarded a multi-year, $10 billion cloud computing contract from the Pentagon. Amazon was the shoo-in for the contract until it wasn't.

Wins like that have been driving shares of Microsoft higher all year. With more of the same expected in 2020, Microsoft is a better buy than Amazon. Read on to learn why.

Microsoft stock going up.

Image source: Getty Images.

Microsoft pays a dividend 

From a pure stock perspective, Microsoft's shares have had a better run in 2019 than cloud rival Amazon. Microsoft's stock is up 56% so far in 2019, while Amazon's shares are 25% higher. Both are trading at lofty prices as we end the year. But Microsoft has something over Amazon: it pays a dividend that yields 1.32%. That makes it attractive to income-seeking investors.

It's also far safer from a trade war with China and is seen as a safe haven during recessionary times because of its corporate software business that brings in recurring revenue. Amazon has a big corporate unit thanks to AWS, but it also has an e-commerce business that's sensitive to a slowdown in the economy and tariffs on goods coming from China.  

On the earnings front, Microsoft has been able to deliver results that beat Wall Street expectations for several quarters in a row. Amazon hasn't been so fortunate. Earnings through the year have been mixed with misses common from one quarter to the next. Take the third quarter as one example. Amazon reported a decline in profit for the first time in over two years and offered up revenue guidance for its fourth quarter that was lower than Wall Street views. The shortfall was blamed on expenses associated with faster shipping and investments in AWS. 

It's all about cloud computing 

On the cloud computing front, Amazon is by far the leader, but it isn't the fastest-growing player as of the third quarter. According to market research firm Canalys, the cloud market increased 37% in the third quarter with Amazon in the first place. It had market share of 33% compared to Microsoft Azure's 17% share. But its growth of 35% in the third quarter was slower than the 59% growth Microsoft's Azure cloud unit saw. 

Microsoft is expected to be more of a competitive threat to Amazon in the coming years, particularly as more companies embrace a hybrid approach to cloud computing. Microsoft has been an early player in offering the ability to keep some programs on-premise and others in the cloud, although AWS is encroaching there with a new AWS Outposts offering. 

Amazon and Microsoft are both aiming to expand their cloud businesses and see the government as a way to do that. That's why the Pentagon contract was so important to both Microsoft and Amazon and why Microsoft's stock gained more than 3% when the deal was announced in late October.

Having the Pentagon as a customer will be a big selling point when trying to land other government contracts, although Amazon is challenging the decision in court. And with the federal government expected to spend $40 billion on cloud computing over the next few years, any edge will be helpful in getting a piece of that. 

Microsoft poised to win in 2020 

Looking out to 2020, it's expected to be a big year for Microsoft in terms of cloud growth. As more companies move some or all of their applications to the cloud, Microsoft is poised to benefit. It's one of the reasons Bank of America just named it among its software picks for 2020, upping its price target on the stock to $200 from $162. If that proves correct, it means Microsoft has another 26.5% to rise. 

Bank of America thinks Microsoft's Azure unit will account for more than 40% of its annual growth in the years to come. Wall Street predicted Microsoft will continue to lodge growth of more than 10% annually for the years to come, with the cloud business eventually trumping the Windows PC and server businesses. 

With the cloud market forecast to grow 17% in 2020 and with Microsoft expected to be a big beneficiary, it's a better buy than Amazon for 2020.