Just about every company feels the impact of a recession, or slowdown in the economy, in some way. They can plan for it, but they can't avoid it. Similarly, it's not realistic to structure your stock portfolio to avoid all losses during a bear market. Even Warren Buffett's portfolio takes a hit in some way when a bear market comes along. The best you can do is adopt a long-term attitude toward the investments you make.

For long-term investors, what's more important than stock performance is the performance of the underlying business. A business that can still grow revenue in a tough economy is obviously one you should want to invest in for the long term. It will likely perform that much better in a booming economy and generate market-beating returns, even in a bull market.

Here are two tech stocks you might want to consider buying if the stock market falls over a recession.

1. CrowdStrike

Owning shares of businesses that generate recurring, year-round revenue from subscription services is ideal in a recession. It's even better when you invest in a subscription-based business that is delivering high growth in annual revenue. This is why investors looking for a top tech stock to hold in an uncertain economy should consider CrowdStrike (CRWD 1.68%), a leader in cybersecurity software.

Despite all the disruptions the economy faced over the last few years with inflation, supply chain bottlenecks, and rising interest rates, CrowdStrike grew revenue from $481 billion in fiscal 2020 to $2.2 billion through fiscal 2023. Cybersecurity is a must-have, especially as organizations migrate their data systems to cloud servers. Cloud computing brings a lot of efficiencies for companies, but the downside is it exposes company data to cyber-attacks. This growing threat is driving demand for cybersecurity solutions.

CrowdStrike is becoming the go-to choice in this market. Its cloud-based Falcon platform uses artificial intelligence (AI) to protect against threats across endpoint devices, cloud workloads, and data. It posted a 37% year-over-year increase in revenue last quarter. Management is landing large deals with major organizations across financial services, technology, retail, and manufacturing. Wall Street analysts expect full-year revenue to grow 35% to $3.04 billion, consistent with company guidance.  

The stock price has climbed 67% year to date, but it's not too late for investors to jump on board. CrowdStrike is seeing an expanding growth opportunity as it launches new services on its platform. Management sees its addressable market being worth $158 billion by 2026, so the company should be able to grow at high rates for several more years and fuel market-beating gains for investors.

2. Microsoft

Microsoft (MSFT 0.11%) has changed a lot over the last decade. It no longer depends on selling individual software products for every device its customers use. It now sells its flagship Office software, and many other services for consumers and businesses, as a subscription. The strength of the Microsoft brand and subscription-based business strategy make the stock a solid investment for any economic environment.

High-margin revenue streams from software services have made Microsoft a financial fortress. Over the last 10 years, it grew revenue and earnings per share at 10% and 14% per year, respectively. On a trailing 12-month basis, Microsoft generated a whopping $59 billion of annual free cash flow on $211 billion in revenue, and it should continue to grow. The ongoing shift from licensed product sales to subscriptions appears to still have legs for long-term growth, as it drove a 13% year-over-year increase in revenue for Office 365 last year. 

Microsoft is also continuing to post strong growth across its offering of commercial cloud services, with Microsoft Azure ranking as the second-largest provider behind Amazon Web Services. Microsoft Cloud revenue grew 22% last year to $111 billion, comprising most of its total revenue. 

Solid growth prospects in productivity software and cloud services have pushed the stock price up 37% this year, but Microsoft is using its cash resources to further widen its advantage. Following its investments in ChatGPT creator OpenAI, Microsoft has started to introduce new AI tools across its software offerings, which should lead to more growth and ultimately benefit the stock for years to come.