Fears of a recession are receding, but that doesn't mean consumers are totally out of the woods.

The office real estate market is teetering, jeopardizing the loans and the banks attached to it, the Federal Reserve reportedly still plans to raise interest rates twice more this year, and consumers are facing higher prices for items ranging from housing to food after two years of unusually high inflation.

Even if a recession doesn't happen, it's always good to have some safe stocks to count on in an economic downturn. While the tech sector tends to be cyclical, there are a few tech stocks worth buying when the economy goes into the red.

1. Airbnb

Airbnb (ABNB 0.75%) might seem like an odd choice for a stock to buy in a recession as the travel sector is generally cyclical, but Airbnb has an ace up its sleeve in a downturn.

Hosts turn to Airbnb as a way to make money, meaning interest in hosting benefits from a tailwind in a challenging economy.

For example, in the third quarter of last year, when inflation and a "cost-of-living crisis" were weighing on much of the world, Airbnb said single-room listings jumped 31% as people turned to the platform as a way to make extra cash.

Over the long term, expanding supply may be the most important driver to its growth, so a recession could benefit the company if it brings more hosts onto the platform.

In addition, those single-room listings help distinguish the company from its closest competitor, Expedia's Vrbo, which advertises that it lists only whole vacation homes on its platform, as opposed to individual rooms. That positioning also gives Airbnb an advantage with budget travelers, as it will have more affordable options on its website.

Similarly, Airbnb has much more price flexibility than hotel chains, since hosts are likely to lower rates in a recessionary environment or new inventory will appear on the website to match demand, much as it did during the pandemic, when demand shifted to rural areas and for long-term stays.

Overall, Airbnb should be resilient in a recession, and the flexibility of its business model should help it capture market share and grow its base of hosts.

2. Okta

Software-as-a-service stocks got crushed during the bear market in 2022, and Okta (OKTA -0.69%) was unable to escape the pain. It fell more than 80% from peak to trough. 

However, much of that sell-off can be traced to the company's premium valuation after the stock soared during the pandemic, and the stock is now trading at a much more reasonable price-to-sales ratio of less than 6.

But that's not the only reason Okta is worth picking up during a recession. The company's business is cloud identity software, which means it helps companies seamlessly and securely log in and stay connected to the applications they need across multiple devices. 

Identity is generally considered a subsector of cybersecurity, which is a need for businesses rather than a luxury, and it's not an area that they're likely to ignore even in a recession.

Okta also quickly responded to investor demands that it scale back costs and demonstrate profitability. Accordingly, the company has crushed bottom-line estimates over the past few quarters.

As of its most recent earnings report, the company expects to earn nearly $1 per share on an adjusted basis this year, a significant improvement from a year ago.

Software sales tend to be based on seat licenses, meaning growth can slow during a recession since companies are less likely to be hiring, but Okta has a recession-proof product, a management team that has shown its ability to adapt to new circumstances, and an attractive valuation for a growth stock.

It's a stock worth buying if the economy sinks into a downturn.