Swiggy Jan 17, 2023

Video Stories and Caching Mechanism (iOS)

Article Summary

Swiggy's iOS team built Instagram-style video stories and saved 49GB of user data in just two weeks. Here's how they did it.

Agam Mahajan from Swiggy's mobile team breaks down their implementation of a multi-video stories feature with intelligent caching. The solution handles seamless autoplay, gesture navigation, and persistent video storage to reduce both server load and user data consumption.

Key Takeaways

Critical Insight

By combining session-based video loading with persistent local caching, Swiggy reduced user data consumption by tens of gigabytes while delivering smooth Instagram-like video experiences.

The article includes specific code patterns for handling video exports and a clever approach to measuring cache impact with New Relic that most teams overlook.

About This Article

Problem

Swiggy wanted to build Instagram-style video stories with smooth autoplay and tap navigation. The challenge was avoiding repeated downloads and unnecessary server calls when users watched the same videos across different sessions.

Solution

Agam Mahajan's team used AVPlayerLayer to create a custom interface, added loadValuesAsynchronously to cache partially watched videos at the session level, and used AVAssetExportSession to save videos directly to the device for persistent storage.

Impact

Within two weeks, the caching system saved 49GB of user data from 20.3K requests at 2.4MB each. The team expects this number to grow significantly throughout the year while also cutting server load and making videos play more smoothly.

Recent from Swiggy

Related Articles