Amazon (AMZN 0.78%) and Microsoft (MSFT 1.37%) both generated big gains for investors this year. Amazon's stock soared more than 80% as its e-commerce and cloud businesses shone throughout the COVID-19 crisis, and Microsoft's stock rallied nearly 50% as its cloud growth offset weaker demand for its enterprise-oriented products.

Can Amazon and Microsoft maintain those big gains? Let's dig deeper into both tech giants to see which tech giant is the better overall investment.

The key differences between Amazon and Microsoft

Amazon generates most of its revenue from its online marketplaces, but most of its profits come from AWS (Amazon Web Services), the world's largest cloud infrastructure platform.

A businessman catches cash raining from a cloud.

Image source: Getty Images.

Amazon subsidizes the growth of its lower-margin marketplaces, and their respective hardware and software ecosystems, with profits from AWS. That's why Amazon can consistently sell products at low prices, launch new hardware devices at low margins, and offer more digital content and perks to expand its Prime ecosystem -- which surpassed 150 million paid subscribers last year.

Microsoft's business consists of three main segments: Productivity and Business Processes, which provides productivity software like Office and Dynamics; the Intelligent Cloud, which includes Azure and its server products; and More Personal Computing, which sells Windows licenses, Xbox consoles and games, and Surface devices.

Last year, Microsoft's "commercial cloud" revenue, which include all its public cloud services, accounted for 40% of its top line. Microsoft's expansion of that business over the past six years under CEO Satya Nadella pivoted the tech giant away from its legacy software products and unlocked new growth engines in the cloud and mobile markets.

How fast are these tech giants growing?

Amazon's revenue and earnings rose 20% and 14%, respectively, in 2019. In the first half of 2020, its revenue climbed 34% as its earnings grew 24%.

Tiny parcels on a laptop keyboard.

Image source: Getty Images.

Amazon's online marketplaces generated robust revenue growth throughout the first half of the year as COVID-19 closures boosted its online sales, but its North America unit's operating profit fell year-over-year, and its international unit remained unprofitable. Those units already operated at low margins, but higher COVID-19 expenses exacerbated the pressure.

However, a 48% year-over-year jump in AWS' operating profits easily offset the lower margins of its e-commerce marketplaces in the first half. It also expects its COVID-19 expenses to decline sequentially in the third quarter.

Amazon didn't provide any guidance for the full year, but analysts expect its revenue and earnings to grow 31% and 37%, respectively.

Microsoft's revenue rose 12% in fiscal 2020, which ended on June 30, as its adjusted earnings grew 14%. The pandemic throttled sales of its enterprise-oriented productivity software as companies cut back their spending, but generated tailwinds for its cloud, Windows, and gaming businesses -- all of which benefited from remote work and stay-at-home measures.

Microsoft's commercial cloud revenue rose 36% to over $50 billion in 2020. That growth was led by Azure, which ranks second in the cloud platform market after AWS. Microsoft doesn't disclose Azure's exact growth rate, but it grew at an average rate of nearly 60% in constant currency terms over the past four quarters.

Microsoft also didn't provide any full-year guidance, but analysts expect its revenue and earnings to rise 10% and 12%, respectively.

The tailwinds and headwinds

Amazon and Microsoft will both benefit from the secular growth of the cloud market, which is well-insulated from macro headwinds like the trade war and COVID-19. Amazon will also profit from the ongoing expansion of the e-commerce market, while Microsoft's gaming growth should accelerate with the launch of the Xbox Series X later this year.

Those tailwinds are strong, but both companies also face unpredictable headwinds. Amazon is growing increasingly dependent on third-party sellers -- some of which have been accused of selling fake products -- to drive its e-commerce sales. New regulations could sever those relationships and throttle Amazon's long-term e-commerce growth. Microsoft's Azure growth also decelerated last quarter, sparking concerns about competition from AWS and other rivals, and the Xbox Series X will likely still face fierce competition from Sony's PS5.

The valuations and verdict

Amazon currently trades at over 110 times forward earnings and it doesn't pay a dividend. Microsoft's stock trades at 35 times forward earnings and it pays a forward yield of 0.9%. Neither stock is cheap relative to its growth, but investors seem to be flocking toward both tech giants as defensive plays.

Amazon and Microsoft are both solid long-term investments, but Microsoft's lower valuation, the upcoming launch of the Xbox Series X, and a potential rebound in its enterprise business after the COVID-19 crisis ends all make it a better buy at current prices.