The royalties Spotify Technology (SPOT -7.28%) has to pay to record labels and songwriters just to stream a song have been its biggest roadblock to reaching profitability. While streaming was once a little side business for record labels, the industry has grown reliant on it for revenue growth. Spotify's 180 million users give it considerable leverage with the record industry.

To that end, Spotify was able to increase its gross margin to 25.8% in the second quarter. That's 90 basis points above its first-quarter gross margin and a 2.8-percentage-point increase from last year's Q2. Earlier this year, management guided for gross margin between 23% and 25% for the full year. While it does expect margin to fall back due to third-quarter seasonality, it looks like Spotify could come in at the high end of that guidance.

Long term, Spotify expects to be able to produce gross margin between 30% and 35%. Considering its 2017 gross margin was just 21%, it's showing excellent progress toward that goal.

Spotify Discover Weekly playlist on desktop.

Image source: Spotify.

How did it get here?

Spotify signed new deals with all three major record labels and independent label representative Merlin between April and August of last year. As part of the new deals, Spotify agreed to provide an exclusive window for some of its new releases to its paid subscribers only before releasing new albums to free listeners as well. In exchange, Spotify pays a lower percentage in royalties.

Spotify wasn't just looking for a price break with these deals. Competitors like Apple have negotiated exclusive windows for blockbuster albums in the past, which encourages customers to sign up. Apple was initially very aggressive with exclusive deals, but the new record label deals with Spotify mitigated that strategy. Still, it's worth noting Apple has managed to overtake Spotify in paid subscribers in the U.S.

While Spotify's new deals may have thwarted one of its rival's competitive advantages (deep pockets for exclusive deals), it will soon lap the financial benefits. It can't rely on the lower royalty rates to further improve gross margin going forward, and investors want to see a path toward 30% gross margin.

Where does Spotify go from here?

There are two primary driving forces for Spotify's gross margin improvement going forward: improving its ad-supported user monetization and cutting out the middle man.

In its second-quarter letter to shareholders, management noted that "Ad-Supported Gross Margins are relatively strong in our developed markets." Emerging markets, however, remain relatively weak. Overall, ad-supported gross margin was 16.3% last quarter, an improvement of 3.6 percentage points year over year. That's better improvement than the 2.8 percentage point increase in overall gross margin.

Further progress in monetizing its emerging market listeners with advertisements ought to help Spotify improve that margin. It should get a natural boost from the secular trend toward digital advertising and the growth of advertising in emerging markets in general. The introduction of its self-serve platform should enable it to attract more advertisers in both emerging and developed markets, leading to higher ad revenue across the board.

Long term, the company highlights its efforts to establish itself as a marketplace where musicians can reach fans directly instead of working through a music label. Spotify's early progress in the area is promising, having grown its Spotify for Artists platform to 200,000 musicians -- a doubling over the last six months.

Spotify is building various tools to help artists promote and market their albums, songs, merchandise, and live shows. It's also building career management tools for independent artists. Eventually, Spotify thinks it could replace the record label for many artists. That would significantly cut down on royalty payments because there wouldn't be any third party taking its cut. Spotify's happy, artists are happy, and everybody that doesn't work for a record label wins.

Both areas are showing strong progress, and investors should expect Spotify's gross margin to keep marching higher over the long term. There will be bumpiness as it runs promotional campaigns throughout the year, so investors should pay closer attention to the year-over-year trends.