2020 has been a disastrous year for the retail industry, but there's one exception.

Essential retailers, especially those focused on consumer staples , have mostly thrived during the pandemic as consumers have flocked to such stores to stock up on goods like food and cleaning supplies. These stores have also benefited from consumers having limited options for spending money other places, as Americans have avoided things like travel and live entertainment.

A scale with two stacks of coins on each end.

Image source: Getty Images.

Costco (NASDAQ:COST) and Dollar Tree (NASDAQ:DLTR) offer two such examples of recession-proof retailers, though they operate with very different business models. Costco is the world's biggest membership-based warehouse retailer, selling bulk goods at bargain prices. Though the company is known for value, its $60 annual membership fee means it appeals to a higher-income demographic than the typical discount chain. Dollar Tree, which also owns Family Dollar, specializes in selling $1 items like toys, books, games, and party supplies at Dollar Tree, and general discount items like food and sundries at Family Dollar.

COST Chart

COST data by YCharts

As you can see from the chart above, Costco has outperformed Dollar Tree by a wide margin this year, but which is the better buy going forward? Let's take a look at what each stock has to offer today.

A rock-solid retailer

It's hard to find a reliable retail stock in this day and age, but Costco has delivered lockstep comparable sales growth for years as it adds new stores around the world, grows its membership base, and expands its profits.

Costco's sales have boomed during the pandemic, as it's been a popular destination for consumers still looking to do in-store shopping, and its e-commerce sales have surged. Comparable sales jumped 14.1%, excluding fuel prices and foreign currency exchange, in its most recent quarter, and e-commerce sales rose 91.3%. Earnings per share, meanwhile, jumped 27% as the company gained leverage from the increase in comparable sales. It also benefited from a boom in fresh food, which carries higher margins, and was able to pass along higher margins in gas as overall gasoline prices fell.

In September, Costco's momentum accelerated as adjusted comparable sales jumped 16.9% on a 90% rise in e-commerce sales.

While the membership-based chain is well-positioned for the current crisis, Costco has been a historic outperformer because of its unique model, which gives it a number of competitive advantages, including rock-bottom prices, and a loyal membership base with a retention rate around 90%. Costco also ranks among retailers with the highest customer satisfaction, and it pays employees above-average wages, helping to keep turnover low. That set of features has allowed Costco to grow steadily and fend off challengers like Amazon even as most other retailers have struggled.

A turnaround in progress

Unlike Costco, which came into the pandemic as a steady retail machine, Dollar Tree has been in the midst of a years-long restructuring following its 2015 acquisition of Family Dollar. The company has invested significantly in renovating Family Dollar stores, though performance has generally been below expectations and the stock has been flat for the last three years.

However, the COVID-19 pandemic seems to have given the business a shot in the arm. In the second quarter, companywide same-store sales rose 7.2%, with an 11.6% gain at Family Dollar as those stores tend to focus more on essentials. Even better, earnings per share jumped 45% in the quarter to $1.10, driven by same-store sales leverage, lower merchandise costs, and fewer markdowns, which more than made up for the $134.9 million in incremental COVID-19-related costs.

Dollar Tree also continues to aggressively open new stores, and the fallout in the retail industry could give it improved real estate options. For 2020, it plans to open 500 new stores, including 325 Dollar Tree locations and 175 Family Dollar locations. It's aiming for 750 Family Dollar renovations under its "H2" format, which includes expanded freezer and cooler doors, wider merchandise selection, and a selection of Dollar Tree items at $1. The company has more than 15,000 stores nationwide, making it one of the biggest retailers in the U.S.

Still, while the pandemic has been a tailwind for the company, questions remain about its ability to deliver growth once the economy normalizes, as shopping patterns may shift away from places like Family Dollar. In 2019, for example, the company only posted modest growth, and that may be why the stock is stuck in neutral despite solid profit growth this year.

Who's the better buy?

It's hard to ignore the consistency of Costco's performance and the strength of its business model, but investors will have to pay up for the stock. It now trades at a price-to-earnings (P/E) of 41.7, its highest valuation in about 20 years -- though that also reflects a stock market whose valuations are generally stretched. Dollar Tree, on the other hand, is priced much more modestly at a P/E of just 19. 

For income investors, Costco is the only one that pays a dividend, currently yielding just 0.7%. But the company also has a history of paying generous special dividends.

Risk-seeking investors may prefer Dollar Tree, as the stock is cheaper and its turnaround strategy could pay off. Additionally, the company should benefit from the recessionary environment over the coming quarters. However, Costco looks like the much safer bet here, especially given Dollar Tree's erratic performance in recent years. September results show the warehouse retailer continues to deliver phenomenal growth during the pandemic, and that should only reinforce its strengths over the coming years. 

Costco looks like a strong candidate for continued outperformance, while Dollar Tree still carries a lot of uncertainty. Costco is the better buy today.