DEV Community

Mohsin Abid
Mohsin Abid

Posted on

How I Built a "For You" Feed Ranking Algorithm in Flutter + Supabase

When I built SARAIKI STAR, my TikTok-style short-video app, the feed could not just be "newest first". With 140+ videos from a handful of creators, a naive feed repeats the same creator endlessly and buries new uploads. Here is the ranking I shipped.

The scoring formula

Every video gets a score in a Postgres function:

score = (likes*3 + comments*5 + shares*4 + saves*2 + views*0.05 + 15) / (age_hours + 2)^1.3

Comments weigh more than likes (they cost the viewer more effort), shares weigh almost as much, and the +15 constant gives brand-new videos a fair chance against old hits. The exponent on age was later raised to 1.3 so fresh content cycles in faster, and I added an engagement-rate term (engagement relative to views) with log-scaled view counts so a viral outlier does not dominate forever.

Two multipliers sit on top:

  • ×1.5 boost for videos younger than 48 hours
  • ×1.8 if the viewer follows the creator, ×0.3 for the viewer's own videos

The diversity pass

Ranking alone still produced runs of the same creator. So the client applies a light interleave after fetching: if the next item's creator is the same as the previous item's, it swaps in the next different creator. One rule, huge perceived difference.

Playback discipline

Ranking is wasted if the feed stutters. The feed only mounts video players for the current and next page, starts playback on the HD rendition directly (no mid-play quality switch — that caused a visible "scene jump" bug), and saves downloads straight to the phone gallery.

The template

The full app became ClipFlow, a complete Flutter + Supabase short-video template (feed, publishing with on-device 720p/480p compression, live streaming with gifts, comments, follows, inbox): https://mohsinabid.gumroad.com/l/clipflow-flutter-template

Its sibling RideBook is a full ride-hailing template: https://mohsinabid.gumroad.com/l/ridebook-flutter-template

Portfolio: https://mohsin-abid-portfolio.netlify.app · GitHub: https://github.com/zemotify415-cyber

Top comments (0)