Market troubles can drag down even well-established corporations with solid long-term prospects. That's what we have seen this year, with many excellent companies failing to escape the downturn. But that also means it's a great time to scoop up solid investments from the discount bin.

Which stocks should investors buy? Here are two excellent options: Microsoft (MSFT -1.27%) and Alphabet (GOOG -1.10%) (GOOGL -1.23%). Read on to learn why both companies are no-brainer buys for long-term investors.

1. Microsoft

Microsoft has been rewarding shareholders with solid performance for years, largely thanks to its dominance in the market for computer operating systems. It remains the leader in that field, but the tech giant's business has evolved. Microsoft's Azure cloud computing unit is growing in prominence and currently stands as one of the leaders in the industry, behind only Amazon.

Cloud computing solutions are becoming increasingly more important for businesses due to the many benefits they offer, including lower costs and higher efficiency and productivity. That's partly why Microsoft's cloud-related sales are growing faster than the rest of its business. During its latest reporting period -- the first quarter of its fiscal 2023, ending on Sept. 30 -- Microsoft's total revenue increased by 11% year over year to $50.1 billion. 

Meanwhile, Azure revenue soared by 35% year over year.

Microsoft's cloud computing won't hit a ceiling anytime soon. It arguably benefits from high switching costs because changing providers isn't easy for businesses and can lead to disruptions. The company also generates more than enough cash to continue pouring funds into this area. It ended its Q1 2023 with $63.3 billion in free cash flow, a 4.35% increase year over year. 

The entire cloud industry is on a solid path forward. Analysts at Grand View Research predict that it will expand at a compound annual growth rate of 15.7% through 2030.

Meanwhile, Microsoft's gaming unit helps complement the rest of its business and confers a degree of diversification. The company is also a leader in this area, and it could get even bigger if its planned acquisition of Activision Blizzard for $68.7 billion in cash goes through.

With or without Activision Blizzard, Microsoft boasts leadership in three industries, solid financial results and cash flow generation, and a nearly impregnable moat. These factors make it an excellent tech stock to buy. 

2. Alphabet 

Alphabet is the parent company of Google, the leading search engine in the world. It generates much of its money through advertising. The company hasn't escaped the recent decrease in ad spending, which may partly explain its poor stock performance this year. But that's a reason to avoid the stock only for those who think the economy will never rebound (along with Alphabet's advertising business). 

Since that is unlikely, Alphabet's future does not seem that dim. The company benefits from a solid network effect through Google, as it can improve and fine-tune search results thanks to the data it collects on search patterns, making its search engine even more accurate and more valuable over time as more people use it. 

Alphabet also owns YouTube, an important player in the streaming industry. We are experiencing a shift in how people consume television, with viewers increasingly spending time on streaming platforms, and YouTube is one of the main beneficiaries. It was responsible for 8.5% of television viewing time in October, which came in ahead of even Netflix.

Many of the largest media companies have leveraged YouTube's rise by seeking to connect with viewers via the platform. That will continue, and it will mean fewer viewers of these media outlets will tune in through traditional cable, and more of them will do so through YouTube, helping it boost viewing time and attract more ad revenue.

Alphabet has also dipped its toes in cloud computing. Alphabet's cloud business has the third-largest market share behind Microsoft and Amazon. Alphabet will benefit from this long-term opportunity as well. Patient investors will want to stick with the company in these difficult times because it can provide outstanding returns over the long haul.

Winners keep winning

A company's track record, although not a guarantee of anything, counts for something. Here is what investors who look at Microsoft and Alphabet's track records will see. Both have survived several downturns over the years, delivered market-thumping returns, and shown their ability to pursue profitable business opportunities while building solid moats.

Investors will want to hold on through the current challenging economic troubles and beyond as Microsoft and Alphabet ride the wave of fast-growing industries for years to come.