Downturns in the stock market are not much fun to live through. After all, nobody likes to lose money. Unfortunately, downturns are inevitable, so the best that investors can do is try to prepare for them as well as possible. One way is to think about companies that might be more resilient during a downturn, but that also will do well in good times.

This isn't an easy task, and there are many factors to consider. Yet, here are two stocks worth considering now. Each has advantages that help them do well in good times but insulate them to some degree in bad times.

1. Costco

The first thing to know about Costco Wholesale (COST 1.01%)is that it has a pretty good track record during bad times in the stock market. Consider how its stock price held up during the Great Financial Crisis compared to the S&P 500.

COST Chart

COST data by YCharts

Customers clearly see the value proposition of a Costco membership when times are tough. However, Costco also does extremely well when times are good. Here's that same chart from the end of the same recession through the end of 2019 -- a time that was mostly a long bull market.

COST Chart

COST data by YCharts

Let's be clear: Past performance is not an indicator of future results. However, Costco has a lot going for it. The company ended its 2023 fiscal year as the third-largest retailer in the world, with 861 locations and $238 billion in annual revenue. And $4.6 billion of that revenue was from membership fees that its customers happily pay. Costco has a membership renewal rate of nearly 93% in the U.S. and Canada.

Recent performance has been impressive as well. For the fourth quarter of the 2023 fiscal year, Costco grew its revenue by 9% and increased its earnings per share by 16%. More impressive is that traffic increased by 5.2% in the fourth quarter. This shows that the growth is being driven by people coming into the stores and not entirely by raising prices. This is an important distinction in a world where many companies are posting higher revenue that are a result of higher input costs being passed along to customers.\

In a market downturn, it's likely that Costco's stock would sell off to some degree. However, any such sell-off would likely represent a compelling buying opportunity for a stock that is rarely cheap.

2. CrowdStrike

Costco's advantage during a market downturn lies in the value proposition it provides to its customers. CrowdStrike's (CRWD 2.03%) advantage is that it's in an indispensable industry: cybersecurity.

Oftentimes, a market slump coincides with a larger recession or downturn in the economy. In such a scenario, companies would feel the pressure and look to cut costs. The last place a cash-strapped business would be looking to cut is cybersecurity. In today's world, cybersecurity is as necessary of an expense as electricity.

During the bull market of late 2020 and 2021, CrowdStrike was growing revenue in the 60% to 80% range quarter after quarter, resulting in a stock price that became unrealistically optimistic. As a result, the bear market of 2022 saw the stock fall as much as 67% off its high. It has since recovered, but still trades 28% lower than it did near the end of 2021.

One might be tempted to think this means that CrowdStrike would be a bad stock to own during a market downturn, but I think nothing could be further from the truth. The sell-off in 2022 was due more to the inflated stock price than it was to the fundamentals of the business. In fact, even as the stock was selling off and revenue growth was slowing, CrowdStrike improved its bottom line and tipped into generally accepted accounting principles (GAAP) profitability for the first time ever this year.

In addition to its impressive turn toward profitability, CrowdStrike continues to prove it has a sticky product that its customers see value in. As of the end of the third quarter of its fiscal 2024, 42% of its customers subscribed to six or more of CrowdStrike's products, and 26% subscribed to seven or more. Those numbers were 36% and 21% in the third quarter of fiscal 2023.

CrowdStrike could remain pricey for the foreseeable future as it's still posting strong growth in an ever-expanding market. The stock still trades for 19 times trailing sales, which is definitely not cheap. However, a potential downturn in the market should provide better valuations to open or add to a position.