A stock market sell-off in 2022 has brought down the share prices of some of the world's most valuable companies. For instance, Microsoft's (MSFT 0.44%) shares have tumbled 26% year to date, while Amazon's (AMZN 1.91%) have fallen 48% in the same period.
As leading companies in some of the most lucrative markets, Microsoft and Amazon are attractive investments amid a sell-off. Microsoft has a considerable market share in cloud computing, computer operating systems, and gaming. Meanwhile, Amazon is the leader in cloud computing and the champ in e-commerce.
As a result, you might be looking at adding at least one of these companies to your portfolio, wondering which is the better buy. So without further ado, let's take a look at each.
Microsoft
Despite a stock dip in 2022, Microsoft shares have risen 195% in the last five years. The company offers investors a diverse business home to top-performing brands such as Windows, Office, Xbox, and Azure, and has expanded its dominance in multiple industries.
Since its CEO Satya Nadella took the reins in 2014, Microsoft has become a true force in the tech world. In fact, the company has seen a compound annual revenue growth rate (CAGR) of 15.4% in the last five years and 12.08% over the last decade.
The company's primary growth driver has been its cloud computing platform, Azure. The service is responsible for the second-biggest market share in the industry at 21%, only behind Amazon Web Services' 34%. In its most recent quarter, Microsoft's intelligent cloud segment rose 20% year over year to $20.3 billion, with operating income earning $8.9 billion.
According to Grand View Research, the cloud computing market will increase at a CAGR of 15.7% until at least 2030. And with that, Microsoft could be in an excellent position to see significant gains over the long term.
Moreover, Microsoft's Windows operating system has held between a 70% and 91% market share since 2013, helping the company grow its software and gaming businesses.
With powerful brands and a discounted stock, Microsoft makes a superb long-term investment.
Amazon
The past year has been challenging for Amazon investors with shares plummeting almost 50%. Macroeconomic headwinds have hit the company hard over the last year. Its cloud computing business, Amazon Web Services (AWS), made up 100% of its operating income in the previous quarter, while its e-commerce business saw earnings slump.
Despite the deep dive in Amazon's stock this year, investors who bought in five years ago are still up as the stock has increased 52% over the past five years, proving its consistency as a growth stock.
While the e-commerce market could suffer in the coming months, with a recession looming in 2023, the $9 trillion industry is still expected to grow at a CAGR of 14.7% until at least 2027. Considering Amazon held a 37.8% leading market share in the e-commerce industry as of June 2022, the company will likely gain the biggest advantage from the market's continued growth.

NASDAQ: AMZN
Key Data Points
Additionally, as the biggest name in cloud computing, AWS is the company's fastest-growing segment. In Q3 2022, AWS revenue grew 27.4% year over year to $20.5 billion, while operating income rose 10.6% to $5.4 billion. AWS is incredibly promising for Amazon's future; despite being the smallest segment, it managed to make up for the $2.89 billion operating loss in the company's e-commerce segment.
Which should you choose?
Amazon's long-term outlook is positive. However, when comparing its price-to-earnings ratio of 82 against Microsoft's more attractive 26, the Windows company offers more value. Furthermore, Amazon's negative $26.3 billion in free cash flow as of Sept. 30, compared to Microsoft's $63.3 billion, makes the Xbox manufacturer feel like a more secure investment for now.
Both companies are home to robust businesses that have permeated their respective industries, making them exciting investments for the long term. However, after a challenging 2022, Microsoft has fared better, making it the superior stock and a solid buy this month.