Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize / Decrease Playlist Latency #25

Open
adambechtold opened this issue Feb 19, 2024 · 4 comments
Open

Optimize / Decrease Playlist Latency #25

adambechtold opened this issue Feb 19, 2024 · 4 comments

Comments

@adambechtold
Copy link
Owner

adambechtold commented Feb 19, 2024

Background

The time it takes to generate a playlist is increasing as the amount of listening history we store grows.

Number of Listeners/Users Total Number of Listen Events Time to Generate Playlist (median/95th percentile)
30 1.5M 0.8s / 1.5s
50 2.5M 1.2s / 4.5s

Goals

  • 🎯 Goal - Playlists appear very quickly when requested by the user
  • 🎯 Goal - The time required to provide a playlist is not directly proportional to the number of listening history events

Example

  • ⚖️ Consideration - We timed the requests using network tools, but this demo provides a more subjective, intuitive sense of that the experience is like as a user
2024.02.19.-.Demo.-.Playlist.Sometimes.Take.A.While.to.Load.mov
@adambechtold
Copy link
Owner Author

adambechtold commented Feb 19, 2024

Approach - Eagerly Generate Playlists and Store in a Cache

It is easy to predict what kind of playlists users will request. For any combination of users, there are only 3 options.

  • User 1 Only
  • User 2 Only
  • Both

▲ Pro - Achieves 🎯 Goal - playlists appear very quickly
▲ Pro - Partially achieves 🎯 Goal - time required is not directly proportional
▼ Con - Does not decrease the actual amount of time required to generate playlists; It just hides it from a user

Variant - When a user visits the taste-comparison page, generate all 3 playlists and store them in a cache

Any time we load the taste-comparison page, create all 3 playlists. When a user requests the actual playlist, just pull it from the cache.

▲ Pro - Easy to implement
▼ Con - Does not address the case when users navigate directly to a taste-comparison with query parameters that specify a playlist

  • 📍 Position - Adam: This is only likely to happen after someone has already visited the page; In which case, the playlists might still be on the cache (depending on the cache size and invalidation policy)

Variant - Every day, create all playlist possibilities, store in a cache

Run a cron job that creates all possible playlists once a day.

▼ Con - The size of the task would grow quickly
▼ Con - Does not address the experience for new users added that day

@adambechtold
Copy link
Owner Author

Approach - Migrate Listening Events into a Time-series Aggregation

Right now, we store each event individually and perform aggregations (counts) for every playlist generation. We may be able to reduce the number of data points if we aggregate individual events into a time-series format.

▲ Pro - Decreases the time required to generate a playlist
▼ Con - Increase data storage
▼ Con - Requires a migration

@adambechtold
Copy link
Owner Author

adambechtold commented Feb 24, 2024

Update - PR #27 - feat: Eagerly load and cache playlists

This PR implemented the approach to Eagerly Generate Playlists and Store in a Cache using the on-page-load variant.

This dramatically increased the speed.

@adambechtold
Copy link
Owner Author

Update - PR #29 - feat: Show loading spinner

This PR didn't decrease latency, but it makes the experience of waiting easier because it's clear something new is coming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant