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
- Used AVPlayerLayer with custom controls instead of AVPlayerViewController for full customization
- loadValuesAsynchronously saves partially watched videos within a session
- AVAssetExportSession exports and caches videos locally for future sessions
- Smart cache management: storage checks, timestamp cleanup, and 10 video limits
- Measured 49GB data saved in 2 weeks (20.3K requests × 2.4MB per video)
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.
About This Article
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.
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.
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.