Prepare for the worst and hope for the best, because sooner or later the stock market will crash again. Since the end of the Great Depression, there have been a dozen times when stocks plunged by double-digit rates, often by 20% or more, or the typical percentage decline that defines a bear market. 

The pandemic-driven drop in 2020 where the stock indices plunged 34% within the span of just a few weeks was the worst on record. The Great Recession of 2007-2009 was one of the longest. Corrections of 10% or more have occurred 27 separate times with the benchmark S&P 500 since the end of World War II.

Person paying out $100 bills into someone's hands.

Image source: Getty Images.

So a stock market crash is inevitable because it is a natural feature of the normal business and investment cycle. No one can forecast exactly when one will strike, but smart investors know it's best to prepare for the eventuality.

It looked like we were heading in that direction at the start of the year, but the market stopped just short of an official correction and then bounced back. Saber-rattling over Ukraine has markets scared again, and the S&P 500 is down 8% year to date, which makes the following tech stock duo timely investments to have in case of a recession.

Amazon driver leaving a delivery on porch

Image source: Amazon.com.

Amazon.com

Amazon.com (AMZN 3.43%) might be like those old American Express (NYSE AXP) commercials: "Don't leave home without it."

The e-commerce giant owns online shopping, accounting for 41.4% of all online spending in the U.S. last year. That's more than five times the share of the next closest competitor, Walmart (WMT -0.08%), which has a 7.1% slice of the pie, and over 50% more of the top nine competitors combined.

And it's not just goods where Amazon has a leading stake. Groceries are becoming an increasingly important component of the overall total, and while it will continue to battle with Walmart for supremacy, analysts at Edge by Ascential expect the e-commerce juggernaut will handily surpass it and nearly double online grocery sales to $26.7 billion in the next five years. By comparison, Walmart is expected to grow its online groceries revenues to just $19.1 billion by 2026.

Yet online selling, which is the biggest revenue contributor, is secondary to Amazon Web Services, its cloud infrastructure division. AWS generated $62.2 billion in sales last year, a 40% increase from the year before, and Amazon says it's on track to deliver $71 billion in sales this year.

It's Amazon's most profitable segment and is responsible for three-quarters of the $25 billion in operating income the company produced last year. With few headwinds buffeting Amazon today, this is a stock that should outperform through good times and bad.

Person putting hard drive into server.

Image source: Getty Images.

Digital Realty Trust

For many of the same reasons Amazon's cloud services business is a winning investment, investors should consider Digital Realty Trust (DLR 0.95%). It's nominally interesting because it's a real estate investment trust (REIT), but more so because it is the biggest owner of data centers in the world, with some 300 facilities across North America, South America, Europe, Asia, and Africa.

Mergers and acquisitions have narrowed the field of data center-focused REITs to just two, Digital Realty and Equinix, and Digital Realty is the larger company.

As much as AWS powers the internet, data centers are its backbone, the central core for every appliance, device, and thing that accesses a network, whether in the cloud or online. They serve as secure warehouses in need of a central depository for the servers and networking equipment that house the data.

Of course, what attracts investors to REITs are their dividends because they're obligated to pay out 90% of their profits to shareholders as dividends. Digital Realty's payout of $4.64 per share currently yields 3.6% annually with a payout ratio of 76%, which, while high, still allows for reinvestment in the business while continuing to reward shareholders.

Third-quarter adjusted funds from operations (AFFO), a critical profitability metric for REITs, increased 9% to $1.60 per share, up from $1.47 per share a year ago. It was primarily pushed higher by the expansion of the PlatformDIGITAL service, its global data center platform in the cloud.

It recently moved to acquire Teraco, a major data center company in Africa, a continent that is seen as a future battleground growth market. And it recently closed on a joint venture with Brookfield Infrastructure Partners to bring PlatformDIGITAL to India, one of the world's largest, most important data center markets.

The stock is down 23% year to date as its acquisitions will provide a short-term hit to AFFO, but it's a long-term play for the REIT. Investors will find a solid, safe haven in Digital Realty Trust if and when a recession strikes.