Building Spotify’s New Web Player

March 25, 2019 Published by José M. Pérez

The purpose of this post is to tell the story of the new Spotify web player. How and why it came to be. We will focus on what the steps were that led to a complete rewrite and how the lessons learned influenced the experience and the tech decisions of the new web player for desktop browsers.

Using the Web to implement Spotify applications at Spotify

Spotify has been using web technologies for a long time. Before tools like Electron became a reality for building hybrid applications, Spotify started using Chromium Embedded Framework (CEF) in 2011 to embed web views on the desktop application. This made it easier to build and iterate on different parts of the application without having to perform full releases. It was also the foundation used to integrate a myriad of third party apps built using web technologies, what we called Spotify Apps.

spotify-desktop-felipe-ribeiro
A web app within the desktop application showing a third party integration – from Felipe Ribeiro’s talk about Javascript @ Spotify at JSConf Iceland 2016

Spotify’s web player was released in 2012 and complemented the experience on desktop devices. It made it possible for users to play music from Spotify as quickly as possible, without needing to download and install any application.

The architecture of the web player followed the same approach as the desktop application. The views were isolated from each other using iframes, and this allowed the teams to iterate on and release them without interfering with the rest of the application.

Early version of Spotify's web player
An early version of Spotify’s web player

In addition, the code for the views was identical on both desktop and web player. Thus, the team working on the Playlist view would implement a new feature, and make it available on the desktop application and the web player, without having to care about the underlying infrastructure.

The architecture of the web player was ideal for consistency between platforms, and fit how the company was organized in feature teams. It also had its drawbacks.

Having iframes for every feature and having that feature load their own JS and CSS might have worked well for the desktop application, which the user downloads bundled with all the resources that it needs. The web player, on the other hand, had to download many resources every time the user navigated between views, which resulted in long load times, which impacted user experience.

Considering a new Web Player

Over the years, we got better at prioritizing a core set of features. With the rise of smartphones, we learned how to strive for removing clutter, properly A/B test features and understand better what was really needed to deliver a good user experience.

In the summer of 2016 we decided to improve the web player. We realized that the architecture of isolated views was difficult to maintain and was preventing us from building a better product. We wanted to go back to basics and support a set of core features (eg playback, library management, and search) and work our way from there.

We found inspiration in the Spotify application for TV and video consoles. This application is a web-based Single Page Application, and uses the Spotify Web API  that combines the access to lots micro services to create a unified interface to manipulate Spotify data. It represented a good example of a light client being built by a single team leveraging existing libraries at Spotify.

spotify-tv
Spotify for TV

We researched the feasibility of upgrading the web player, rewriting view by view. In parallel, we started working on a prototype following a similar architecture to the TV application.

After considering the two approaches, we decided on the latter.

Usually as a company we try to improve existing systems iteratively instead of completely replacing systems with new ones. There were a few key points behind the decision to rewrite the new web player from scratch versus improving the existing one:

  • The system to deliver the code for the views, that worked in isolation from each other, wasn’t used by the desktop application anymore and it was too complex for the web player use case.
  • The web player was based on lots of libraries and frameworks that were quite outdated. Giving every team an isolated environment to run their code also resulted in them choosing different client-side stacks to build their views.
  • The web player was built by multiple teams with over 40 developers but now would be maintained by a dedicated team of 5 developers.
  • It was very slow to iterate upon and experiment, especially when it came to making changes across multiple views like updating the visual style.

The birth of a new Web Player

spotify-web-player
The new web player

We decided not to repeat the mistakes of the past, so before deciding the feature set that the new web player should have, we ran A/B tests on the existing web player. For some users we removed certain features and we measured their impact in user engagement. After getting the results we decided on the bare minimum feature set that we would feel comfortable with releasing and that our users would enjoy.

We built a Minimum Viable Product (MVP) in a few weeks using our new infrastructure based on Spotify’s Web API. During the following months, we carried out extensive user testing and improved the prototype based on the gathered feedback. Once we felt comfortable, we released it to a small percentage of users side-by-side with the existing web player, and checked the performance amongst them closely.

Our hypothesis was proven. The simpler and faster web player outperformed the old web player in all key metrics.

The tech architecture

The new Web Player is in line with the overall Spotify look and feel and is built on HTML5 standards. It drops Flash in favor of Encrypted Media Extensions (EME) for music playback, which is supported natively by most modern browsers. It is fast, even on spotty connections, responsive and we have focused on making it enjoyable to use.

The architecture is based on React + Redux, which has made it easier for us to share components between the views, to have a clear data flow and to improve debuggability and testability. Although the components are not shared with other Spotify clients, we see a trend in other Spotify web development teams who are also embracing a similar approach to building web experiences.

Making the decision to embrace well-known open-source solutions and avoiding using Spotify custom libraries allowed us to onboard new developers quickly. This has led to numerous contributions from web developers from all over the company.

Having a simpler architecture allowed us to experiment faster and add features that didn’t exist in the old Web Player, like Daily Mixes, video and audio podcasts, and Connect. On top of that, we were also able to build fast CI/CD pipelines. Now with every commit the latest version of the web player is reaching our users immediately. Finally, we have a web player leveraging today’s technologies. As an example, we added support for Progressive Web App on Chrome OS, so the web player is installed and run as a regular desktop application.

We are excited to continue building a good product for our users on the web.

The Web Player team.


Tags: