It's no secret that tech stocks have had a rough few months. The Nasdaq Composite is down more than 25% from its all-time high, easily crossing the "bear market" threshold.

While this induces a lot of fear about the future, long-term investors should be strategic about this weakness. Because so many stocks are being sold off aggressively, it opens up opportunities to get into the best names at a much lower price. Two such stocks are Shopify (SHOP -2.37%) and Datadog (DDOG -1.43%). Both recently reported solid quarters and are down over 80% and 50%, respectively, from their all-time highs.

Could now be a once-in-a-lifetime buying opportunity?

Person analyzing data on a computer.

Image source: Getty Images.

1. Shopify

Because of its vast e-commerce tool kit, many businesses flocked to Shopify to establish an online presence during the pandemic. Now that the rush is over, Shopify is seeing a more challenging environment. Its subscription solutions segment was only up 8% year over year, because fewer merchants joined the platform. However, merchant solutions still rose 29% as people continue to move their spending online.

Because merchant solutions is a larger part of Shopify's business, total revenue rose 22% in the first quarter. Management expects more robust growth in the second half of the year since its prior best quarters were in the first half of 2021. With these problematic comparisons behind it, Shopify's growth numbers should look better by the end of this year.

However, its bottom-line numbers will likely remain negative. Shopify's operating expenses grew 67% year over year, pushing its bottom line into the red. Along with some investment losses (which are only paper losses, as they haven't been realized yet), Shopify's loss per diluted share was $11.70 versus a profit of $9.94 one year ago. These headline numbers can be misleading as management fully expected this.

In its outlook, management stated they will "reinvest all of our gross profit dollars back into the business to pursue our multiple paths to growth." This is great news for long-term investors as it reiterates Shopify's commitment to being one of the top solutions for e-commerce available.

Person shipping a package.

Image source: Getty Images.

With a tremendous long-term growth trajectory and a five-year low price-to-sales valuation of 8.3, Shopify is one of the best stocks to buy in this tech bear market.

2. Datadog

While many SaaS (software-as-a-service) stocks are experiencing slowing growth, Datadog is not. The company's software allows customers to understand how its programs are working individually and together. This technology can solve problems before they're noticed by users and generate unique metrics that tie in many technology stacks.

Datadog's offering is unique, because nearly every company can benefit from its platform, whereas some SaaS companies only have niche use cases. This widespread use allowed Datadog to grow revenue 83% to $363 million in the first quarter and guide for 62% growth in the current period. Datadog was also profitable with GAAP net income of $0.03 per share.

But the company isn't optimized for profits yet, so free cash flow is a better metric to gauge its bottom line. During the quarter, Datadog produced $130 million in free cash flow for a 36% margin. This means the company converted 36% of its revenue into cash the business can use going forward.

With solid revenue growth and profitability, Datadog is one of the highest-quality software companies available right now. Its valuation also reflects this fact.

DDOG PS Ratio Chart

Data by YCharts.

At 27 times sales and 98 times free cash flow, Datadog is far from cheap. Any business hiccups or projection misses will cause this stock to decline even further. However, I don't think this is likely as Datadog's solution has many more customers to capture.

As of March 31, Datadog only had 2,250 customers with annual recurring revenue of $100,000 or more, up 60% from last year. The company should have no problem finding more companies that it can sign up for its product, as well as getting some of its other customers to spend more.

Person examining data stacks on a computer.

Image source: Getty Images.

Datadog is a solid long-term pick but could see some continued volatility because of its high valuation. However, its bright prospects far outweigh the potential downside; investors shouldn't overlook the company for this reason.

With the market in disarray, long-term investors can go bargain hunting and pick up some of the best names for cheap. While it may be nerve-racking to buy when the market is down, it has typically proven wise when investors have a holding period of at least five years.