It's safe to say that tech stocks haven't been investors' friends in 2022. Many individual tech names are down 30%, 40%, or even 50%. Even the Nasdaq Composite, a tech-heavy index, is now down nearly 30% in 2022. The Nasdaq Composite hasn't dropped more than 30% any other time over the last decade, showing how painful it is to invest right now. 

However, this drop offers promising buying opportunities for investors who are focused on the long term. Many high-quality businesses are down significantly, despite strong execution. PubMatic (PUBM 2.19%) and Twilio (TWLO 1.08%) are both in this bunch, with shares down 44% and 68% year to date respectively.Here's why these two stocks are worth buying right now. 

1. PubMatic

Publishers looking for help filling their digital ad space while maximizing revenue can often turn to sell-side platforms like PubMatic, which helps connect publishers with advertisers looking to buy ad inventory.

In terms of revenue, the company is roughly half the size of the sell-side leader in the advertising technology (adtech) industry, Magnite. However, the market is large enough for both companies to succeed. PubMatic expects that by 2024, global digital ad spending will reach $627 billion. Currently, it has just 3% to 4% market share of the space.

However, if there is only one long-term winner, consider betting on PubMatic, thanks to the low-cost advantage that could help it outperform Magnite. When adtech companies facilitate ad transactions, they collect data. Competitors like Magnite pay to store this data on third-party or public clouds, but PubMatic built its own infrastructure internally. This was likely expensive initially, but it is now significantly cheaper for PubMatic to store and use data, which allowed the company to boast a 9% net income margin and a 31% adjusted EBITDA (earnings before interest, taxes, depreciation, and amortization) margin in the first quarter. Comparatively, Magnite's net income margin was negative 38%, and its adjusted EBITDA margin was 27% in Q1.

Of course, a recession could damage the company to some extent. After all, if businesses need to cut back on spending, advertising is easy to pull back. PubMatic makes money based on the number of impressions it facilitates, so with fewer purchases of advertising inventory, PubMatic will facilitate fewer ad impressions and receive less revenue.

That said, the long-term future for PubMatic looks incredibly bright. At just 19.5 times free cash flow, shares are trading on the cheap given the substantial market ahead and its resilient competitive advantages. If you're willing to see through the dark clouds in the short term and weather a potential recession, you could see great returns over the long haul by owning PubMatic.

2. Twilio

As competition heats up in many consumer-facing industries, it is becoming more critical for businesses to have open lines of communication with consumers. Engaging with consumers is a great way to build brand loyalty, and with over 268,000 active customers, Twilio is leading this charge in more open business-to-consumer communications. 

Twilio's main appeal is that it sits at the corner of simplicity and power. Its application programming interfaces (APIs) are simple enough for any developer to get started with, yet strong enough to power large applications at scale. This is why the company has an impressive customer list, including Airbnb and Salesforce

Additionally, the company offers more than just communications. Since it recently acquired Segment, Twilio can now offer a customer data platform in which companies can gather data to power personalized messaging and communication. This adds one more layer of value to Twilio's platform, which could help the company win over the long term. Co-founder and CEO Jeff Lawson said in a May statement that he sees sustained adoption and believes Twilio can organically increase revenue by 30% annually through 2024.

Twilio's acquisitive nature and unprofitability are concerns, but both are becoming less alarming. Twilio is known for making lots of tuck-in acquisitions, which poses a risk to the company's organic growth. However, since the company is anticipating 30% organic expansion for the next few years, it's clear that Twilio's future acquisitions will supplement its adoption, rather than be the sole driver. 

The other risk has been its continued unprofitability, but Lawson said he expects his company to deliver annual non-GAAP (adjusted) operating profitability consistently starting in 2023.

If the company can keep realize its expectations for operating profits and organic expansion, shares look like a steal today at 4.8 times sales. After developing a lead in this industry, Twilio is seeing the fruits of its labor as profits start flowing in and its top line steadily improves. This combination is attractive for the long term, and today's prices allow investors to get in at cheap prices.