Consumers are struggling under the pressures of high inflation and rising interest rates this year. That's having knock-on effects for companies that sell big-ticket items, as well as those that rely on advertising to generate revenue.

These challenges are making life particularly difficult for Microsoft (MSFT 1.44%) and Google parent Alphabet (GOOGL 0.66%) (GOOG 0.56%). Even though the value of both companies steadily declined in 2022, they're still worth $1.8 trillion and $1.2 trillion, respectively, and they're retaining their positions as two of the largest companies in the world. 

How do these two stocks maintain their dominance in this difficult economy? By having multiple, diverse revenue streams, where one or two key business units pick up the slack from the others that are suffering. With 2023 right around the corner, investors should consider buying Microsoft and Alphabet stocks. Let's look at the reasons why.

1. Microsoft is soaring through the cloud

Microsoft has a well-established portfolio of consumer brands, featuring the Windows operating system, the Office 365 document suite, the Surface line of notebook computers, and the Xbox gaming console. The latter two are under the most pressure, with device sales softening in recent quarters and user engagement in the Xbox ecosystem falling as society shifts back toward pre-pandemic habits.

But this year is all about the cloud for Microsoft (though, to be honest, this has been the case for the past several years). Its intelligent-cloud segment is the largest of the company's three core business units, as the corporate sector continues to shift operations online. Microsoft's Azure cloud services platform grew its revenue by 35% in the recent first quarter of fiscal 2023 (ended Sept. 30), which was triple the 11% growth rate for the company's overall revenue.

Azure offers hundreds of solutions to its business customers, from simple data storage to virtual machines to artificial intelligence, and the platform is ranked second in the industry behind Amazon Web Services. That's important because the cloud computing opportunity is estimated to be worth $484 billion this year but could grow to over $1.5 trillion annually by 2030 (according to Grand View Research).

That's a compound annual growth rate of 15.7%. Since Azure is already growing significantly faster than that, it suggests it's acquiring market share along the way.

While Microsoft experienced softness in its consumer-centric segments this year, the cloud  enabled the entire company to maintain a comfortable growth rate. But since there are already signs that inflationary pressures are easing, Microsoft's lagging businesses could see a resurgence as we enter 2023. 

Now might be an opportune time to buy Microsoft stock since it's trading at a 31% discount from its all-time high.

2. Alphabet: Keep watching YouTube (not literally, of course)

Alphabet is a key barometer for the advertising sector because almost its entire business relies on ad dollars to generate revenue. It's the parent company of Google, which still drives the whole organization, financially speaking, particularly through its market-leading search engine. But amid the weakening economy this year, businesses trimmed their marketing budgets, which led to a material slowdown in Alphabet's revenue growth.

When a business observes broader economic weakness, it makes the safe assumption that consumers will have less spending power and the company will receive a smaller return on investment when it comes to advertising. As a result, Google Search revenue grew by just 4.2% year over year in the recent third quarter (ended Sept. 30). For context, it grew 10 times faster (44%) in the same quarter last year when the economy was roaring on the back of stimulus dollars and low interest rates.

Similarly, Alphabet's YouTube video platform saw a 1.8% year-over-year decrease in advertising revenue during Q3 but is currently in the midst of an important transition. YouTube launched "Shorts" two years ago to compete with ByteDance's TikTok, which has swept the globe with its highly engaging short-form mobile video app. Shorts has been a major success, attracting 1.5 billion monthly users and 30 billion daily video views.

The challenge is that short-form video monetizes at a lower rate than longer content. Since Shorts is cannibalizing the traditional YouTube video formats, the platform brought in less money recently.

This will improve in 2023 as Alphabet makes premium content creation more lucrative for YouTube users because higher-quality content means higher prices for advertising spots. Plus, it's exploring new opportunities like shopping, which allows creators to link to products in their videos, bridging the gap between social media and e-commerce

While YouTube made up just 10.2% of Alphabet's total revenue in Q3, investors should expect it to be a more significant part of the company in the future as Shorts continues to grow. That's because short-form video engages a very young audience, which is a coveted factor for advertisers. But looking at the bigger picture, if the economy improves in 2023, Google Search should also roar back to life and supercharge Alphabet.

With the stock price down 35% from its all-time high, this might be a great time to buy ahead of the new year.