The last few years have been a rollercoaster ride for long-term investors. The S&P 500 index reached all-time highs as the world emerged from the pandemic, then spent much of 2022 in a bear market. Now the index is up 27% from its October lows, and many investors are optimistic that we may be in a new bull market.

Despite the recent market rally, there is still some uncertainty about the near future. Interest rates are at their highest point in two decades, affecting everything from commercial real estate to bank lending. Moody's pointed to the risk from higher interest rates when it recently downgraded several regional bank stocks.

As long-term investors, we can't obsess over every potential risk that could lead to a market sell-off. Investing is a long-term game, and one smart thing you can do is invest in quality companies that can ride out market crashes and thrive during long bull markets. Three stocks that could be a safe bet if we do get a market crash are Visa (V -0.23%), Marsh & McLennan (MMC -1.75%), and Walmart (WMT -0.08%).

1. Visa

Visa operates the world's largest payment network, processing over $13.5 trillion in total volume in 2021. This volume was nearly twice as much as Mastercard ($7.7 trillion) and 10 times as much as American Express ($1.3 trillion). Visa is the most widely accepted payment network worldwide and continues growing through its Visa-branded products. This strong network effect gives it a significant competitive advantage over its peers.

As noted in the intro, there are some concerns about the effect of higher interest rates, which have reached a multi-decade high. These high interest rates come at a time when consumer credit card debt tops $1 trillion for the first time in the U.S., according to the Federal Reserve Bank of New York. 

A downturn could slow consumer spending, cutting into Visa's revenue. However, Visa is entrenched in spending and continues expanding its capabilities. The company recently acquired Pismo, a payment platform with operations in Latin America, Asia Pacific, and Europe. The move should help Visa launch innovative payment and banking products, helping it keep up with fintechs offering similar services. 

Another positive of Visa's business is that it doesn't hold on to credit card debt like some competitors. Visa's primary focus is operating its payment networks and collecting a small fee on every transaction to make that happen. As a result, it isn't exposed to the same credit risks others could experience if there is an economic downturn.

Visa has a dominant payment network and continues to expand its services to compete with fintechs and protect (or even grow) its market share. The company will benefit from the growing trend toward cashless payments, and its strong network effects make this stock a solid one to own even if we get a market crash.

2. Marsh & McLennan

In recent years, companies have dealt with a lot of uncertainty, including the pandemic, supply chain issues, capital market volatility, climate-related disasters, and geopolitical risks. It's in this environment where Marsh & McLennan thrives.

Marsh & McLennan advises companies on managing risks and connects companies with insurers to help protect against those risks. It also provides consulting services to companies to help deal with compensation and benefits, retirement plans, managing investments, and other workplace issues.

The consultant has seen solid business growth in recent years, led by its insurance brokerage business. Insurance is a product that will always be in demand, and its brokerage business is a steady source of cash flows that can help it weather challenging economic environments. The inflationary environment, in particular, has been a tailwind for its insurance brokerage business.

According to its Marsh Global Insurance Market Index, global commercial insurance prices have risen for 23 consecutive quarters. Marsh earns commissions and fees from insurers when it refers clients to them, and as insurance prices rise, so do its earnings. The company's risk and insurance services revenue has grown 11% through six months this year, helping total revenue increase by 8% compared to last year. 

CEO Dan Glaser told investors that "when the world is unsettled, the demand for our services rises." He also pointed out that the company has grown its earnings per share during every recessionary period since 1962 -- making Marsh & McLennan another safe bet to own during a potential market crash.

3. Walmart

Market crashes tend to happen during times of economic weakness. And it's during economic weakness that a company like Walmart thrives.

Walmart is the largest retailer in the world, and its business model of being a low-cost provider of consumer goods makes it a go-to retailer when customers tighten their belts. It also operates Sam's Club, a membership-only warehouse that competes with Costco and BJ's Wholesale Club. Last year, customers turned to the retailer to save money during one of the highest inflationary periods since the 1980s. During the year, comparable sales were up 7% at Walmart and 14.6% at Sam's Club.  

Walmart continues to do well in today's economy, where consumer spending sends mixed signals. In its most recent earnings, Walmart saw solid growth, with grocery and pharmacy leading the way, while general merchandise sales fell. People are prioritizing non-discretionary purchases, which has hurt some competitors like Target, which relies heavily on discretionary spending for growth. While Target lowered its earnings guidance for the year, Walmart raised its guidance.

Walmart is a go-to low-cost retailer of choice for many people because of its wide range of affordable product offerings. If we do experience a market crash, Walmart is another safe stock to own to help you ride out the market volatility.