Recessions affect everyone differently, but one common theme is a spending reduction, whether business or personal. Some items are more essential than others, and the key to successful investing is identifying what customers can't live without.

Two stocks that I think make excellent buys during a recession (and even in non-recession times) are Costco Wholesale (COST -0.37%) and Home Depot (HD 0.43%). Both companies have vital product lines and shouldn't experience the same revenue drop as others.

Costco

During a recession, consumers look for any way they can to save a few dollars. Costco's wholesale warehouses are a great place to accomplish that task. Whether it's the discounted fuel or buying items in bulk, Costco provides a great value proposition to customers for a mere $60 annual membership.

Image of a Costco ware.

Image source: Costco Wholesale. Image courtesy of Costco Wholesale. 

The consumer has been weakening over the past few months, but Costco's sales keep ticking up. For the five-week retail month of June, Costco saw U.S. sales rise 21.5% compared to last year's numbers. These results were skewed by an extra day compared to last year, which added an extra 3% growth. Still, 18.5% growth for a commerce giant like Costco is impressive. It's also about 2% faster than Costco's sales have risen over the past 44 weeks, indicating consumers are choosing options that may save them money over the long haul.

We can also look to history to see how Costco might manage in the current economic environment. During the last major recession in 2008 and 2009, Costco's revenue hardly dipped at all:

COST Revenue (TTM) Chart

COST Revenue (TTM) data by YCharts

Costco is an excellent business in regular times and a hardy one during difficult ones. Many other investors recognize this, which is why Costco's stock trades at a premium valuation of 39 times earnings.

Great companies rarely come cheap, and Costco is one of those companies. However, with its sticky membership (92.3% renewal rate in the U.S. and Canada during its third quarter, ended March 31), investors can rest easy with Costco in their portfolio during recessionary times.

Home Depot

Nothing in a house is built to last forever; eventually, something will break. This is where Home Depot comes in. With its vast network of building supply warehouses, Home Depot specializes in everything construction related. So while consumers may be a bit more reluctant to spend on big remodels, everyday projects and upgrades keep them coming back to the store each weekend.

With the current state of the housing market and mortgage rates, few consumers are looking to get out of their homes since they have locked in low mortgage rates at much lower home valuations. Even if they decided to move, they likely couldn't find many affordable homes.

US Average New Home Sales Price / Per Capita Disposable Income Chart

US Average New Home Sales Price / Per Capita Disposable Income data by YCharts

The chart above indicates that home prices, when compared to disposable income, are at their all-time high during this century. This indicates that many consumers will likely stay in their older homes, benefiting Home Depot. 

To be clear, this doesn't mean Home Depot will become the next rocket-ship growth stock. Instead, it will allow it to grow its sales and earnings marginally while paying a solid dividend and repurchasing stock.

During Q1, Home Depot only reported 3.8% and 6.2% sales and earnings-per-share growth, respectively. For the full year, it raised annual revenue growth guidance to 3% and diluted earnings per share to the mid-single digits. Throw in Home Depot's share repurchase activities and a 2.5% dividend yield, and you've got a stock that can weather any recession.

With the stock trading for 18 times earnings, it's at the lowest level since the Great Recession in 2009. Home Depot is poised to maintain its sales growth through difficult times and boom once the economy recovers due to the state of the housing market.

Costco and Home Depot are reliable companies that make excellent portfolio stabilizers during good times. Even during recessions, these companies provide relatively safe havens for investors to keep their money (as long as it's not needed for the next three to five years).