Microsoft (MSFT -1.84%) and Google's parent company Alphabet (GOOG 0.37%) (GOOGL 0.35%) have both generated impressive gains for patient investors. Over the past five years, Microsoft's stock nearly quadrupled as it aggressively expanded its cloud-based services and mobile apps. Alphabet's stock rallied roughly 170% as Google's advertising business, its cloud platform, and YouTube fired on all cylinders.

However, both stocks pulled back about 20% this year as inflation, rising interest rates, and other macroeconomic headwinds rattled the market. Should investors consider investing in either tech giant right now?

An investor checks a portfolio on a laptop.

Image source: Getty Images.

Microsoft's cloud business continues to grow

Microsoft's revenue rose 18% to $168.1 billion in fiscal 2021 (ended June 30), as its earnings per share (EPS) increased 40%. The tech company initially grappled with slower demand for its enterprise-facing software and services as the pandemic spread, but subsequent stay-at-home measures generated tailwinds for its cloud-based services, Xbox gaming business, and Surface devices.

Its total cloud revenue rose 34% to more than $69 billion for the full year, accounting for 41% of its top line. That growth was mainly driven by Microsoft's cloud infrastructure platform Azure, its productivity suite Office 365, and its customer relationship management (CRM) platform Dynamics 365. Its operating margin also jumped 460 basis points to 41.6%.

That momentum has continued in fiscal 2022. The tech giant's revenue rose 20% year-over-year to $164.4 billion in the first nine months of the fiscal year as its total cloud revenue increased by more than 30% throughout all three quarters. Its operating margin rose 120 basis points to 42.9%, and EPS grew 26% -- even as the company incurred some investment-related losses in the third quarter.

For the full year, analysts expect Microsoft's revenue and earnings to grow 18% and 16%, respectively. Next fiscal year, they expect Alphabet revenue to increase 14% and earnings to jump 15%.

After its recent sell off, Microsoft's stock currently trades at a reasonable 25 times forward earnings, and it pays a forward yield of 0.9%. It also returned 61% of its $20 billion in free cash flow (FCF) to investors through buybacks and dividends in its most recent quarter.

Alphabet faces more near-term headwinds

Alphabet's revenue rose 41% to $257.6 billion in 2021. Its advertising business heated up as the pandemic-related headwinds faded, and the company benefited from an easy comparison to the pandemic's initial impact in 2020. Its operating margin expanded seven percentage points to 31%, and its EPS soared 91%. 

The company's various segments individually thrived in 2021. Google's advertising revenue rose 43% to $209.5 billion over the year. Google Cloud, which served as Alphabet's main growth engine throughout the pandemic, grew its revenue by 47% to $19.2 billion.

However, Alphabet's growth cooled off a bit in the first quarter of 2022 as it lapped that post-lockdown recovery. Total revenue rose 23% year-over-year to $68.01 billion, and operating margins stayed nearly flat at 30%. EPS fell 6%, but just like Microsoft, that decline was caused by its investment-related losses instead of significantly higher operating expenses. Advertising revenue from Google rose 22% to $54.6 billion in the first quarter of 2022. Google Cloud revenue also rose, climbing 44% to $5.8 billion. 

Analysts expect Alphabet's revenue and earnings to grow 18% and 3%, respectively, this year. Next year they expect its revenue and earnings to increase by 16% and 18%, respectively. Based on those expectations, Alphabet's stock looks historically cheap at just 20 times forward earnings.

Alphabet doesn't pay a dividend, but it spent 58% of its $89 billion in FCF on buybacks over the past 12 months. It also just added another $70 billion to that buyback plan -- which implies its stock is still cheap at these levels.

The better buy: Microsoft

Microsoft and Alphabet are both great buys at these prices. But if I had to choose one over the other, I'd stick with Microsoft for three simple reasons: Its business is better diversified, its cloud business is larger, and it isn't as sensitive to macroeconomic headwinds as Google's advertising business.