How does Spotify codes work if the design is so simple?

585 views

If you don’t know what I’m talking about it’s this [here](https://community.spotify.com/t5/Subscriptions/QR-Codes-for-tattoo/td-p/4693922) People can draw them on paper and they still work. They seem to work well and are very simplistic. And there are over 50 millions songs on Spotify, and infinite playlists. How does this work?

In: Technology

3 Answers

Anonymous 0 Comments

This is the patent: https://data.epo.org/publication-server/rest/v1.0/publication-dates/20190220/patents/EP3444755NWA1/document.pdf.

From the patent, here’s basically what happens. There are identifying marks in the code that let the software figure out the relative size of each bar. The tallest bar is in the middle, and the leftmost and rightmost bar are the shortest. Then, the other bars are ranked from 0 to 7 on how tall they are in relation to the references.

It seems like Spotify is using 23 bars as standard, but the patent notes these can be arbitrarily large. Currently, that leaves us with 8^20 different combinations. A parsed code looks like: 53526254731226474112

This is actually tiny when dealing with URLs. For example, that is not enough to encode the URL “https://www.reddit.com/r/explainlikeimfive/comments/irpfly/eli5_how_does_spotify_codes_work_if_the_design_is/”. The patent refers to using a random number or index counter that is associated on the server with the code. Essentially, this means that somewhere, there is a massive table that contains all the codes generated and links them to what they are supposed to refer you to.

Note: This sounds really inefficient because there’s a table running out there with at least 50 million code-song pairs, and more likely billions because of profiles, playlists, etc. In actuality, there are very efficient ways of dealing with this problem, and while billions sounds like a lot, on an enterprise scale, it’s minuscule.

Anonymous 0 Comments

There are 23 bars, that can have 8 different sizes. The first and last bar are always the smallest size, and the middle bar is always the largest size (this is done for calibration). That leaves 20 ‘information’ bars with 8 possibilities each, which can have 8^20 unique combinations.

Anonymous 0 Comments

There are over 20 lines of varying sizes in one of those. You can arrange 20 things in over 2 quintillion ways (2 followed by 18 zeroes).

Spotify has a long way to go before they run out of codes. If they do, they can just add another line in the code, and now they have 3 more quintillion codes.

Edit: yes I was too lazy to count the actual number of lines.