iOS System Design Interview Questions
Published:
This is the raw content that will be encrypted. You can edit this file with your actual questions.
๐ฑ Question 1: Design an Instagram-like Feed Hard
๐ฏ Problem Statement:
Design the architecture for an Instagram-like feed that can:
- Display images and videos efficiently
- Support infinite scrolling with pagination
- Handle offline mode and caching
- Optimize for battery life and data usage
- Scale to millions of users
๐ Key Considerations:
- Memory Management: How to prevent OOM with images?
- Prefetching: When and how much to prefetch?
- Caching Strategy: Disk vs memory, eviction policies
- Video Playback: Autoplay, preloading, battery impact
- Network Optimization: Request batching, retries, CDN
โ Expected Solution Components:
- Architecture: MVVM with Coordinator pattern
- Data Layer: Repository pattern with caching
- Image Loading: SDWebImage or custom solution with NSCache
- Prefetching: UITableViewDataSourcePrefetching
- Video: AVPlayer pool, reuse strategy
- Pagination: Cursor-based or offset-based
- Offline: Core Data or Realm for persistence
๐ก Pro Tips:
- Discuss trade-offs: memory vs network vs UX
- Mention
UICollectionView
vsUITableView
choice - Talk about cell reuse and performance
- Consider accessibility and VoiceOver
๐ Question 2: Design a Real-Time Chat System Hard
๐ฏ Problem Statement:
Design a WhatsApp-like messaging system for iOS:
- Real-time message delivery (WebSocket)
- Local message storage and sync
- Media sharing (images, videos, files)
- Typing indicators and read receipts
- Offline message queuing
๐ Key Considerations:
- Networking: WebSocket vs long polling?
- Database: Core Data vs Realm vs SQLite?
- Sync Strategy: How to handle offline/online transitions?
- Message Ordering: Timestamps, local vs server time
- Encryption: E2E encryption approach
โ Solution Architecture:
- Transport Layer: URLSession WebSocket with reconnection logic
- Message Queue: Pending, sent, delivered, read states
- Local Storage: Core Data with background contexts
- Media Upload: Background URLSession with progress tracking
- Push Notifications: APNs for background delivery
๐ผ๏ธ Question 3: Image Caching System Medium
๐ฏ Problem Statement:
Design an efficient image caching system that:
- Downloads and caches images from URLs
- Manages memory and disk cache
- Handles cache eviction intelligently
- Supports image transformations (resize, crop)
- Thread-safe operations
โ Key Components:
class ImageCache {
private let memoryCache: NSCache<NSString, UIImage>
private let diskCache: FileManager
private let downloadQueue: OperationQueue
func loadImage(url: URL, completion: @escaping (UIImage?) -> Void)
func clearCache(olderThan: TimeInterval)
func prefetch(urls: [URL])
}
๐ก Discussion Points:
- Cache eviction: LRU vs LFU vs TTL
- Disk cache size limits and cleanup
- Image format optimization (WebP, HEIC)
- Concurrent downloads and request deduplication
โก Question 4: App Launch Optimization Hard
๐ฏ Problem Statement:
Your app takes 3 seconds to launch. How do you reduce it to under 1 second?
๐ Investigation Steps:
- Measure: Use Instruments (Time Profiler, System Trace)
- Identify: What's happening during launch?
- Pre-main time (dyld loading)
- Main thread initialization
- First view controller creation
โ Optimization Strategies:
- Reduce dyld time: Minimize dynamic frameworks, use static linking
- Defer work: Move non-critical init to background or after first frame
- Lazy loading: Initialize only what's needed for first screen
- Async operations: Use GCD for parallel initialization
- Asset optimization: Compress images, use asset catalogs
๐งต Question 5: Main Thread Optimization Medium
๐ฏ Problem Statement:
Your app's scrolling is janky. Frame rate drops to 30 FPS. How do you fix it?
๐ Debugging Approach:
- Use Instruments (Core Animation, Time Profiler)
- Enable "Color Offscreen-Rendered" in simulator
- Check for main thread blocking operations
- Measure cell prepare time
โ Common Solutions:
- Move to background: Image decoding, text sizing, layout calculations
- Optimize layers: Reduce layer count, avoid offscreen rendering
- Cell optimization: Reuse cells properly, pre-calculate heights
- Rendering: Use
CALayer
directly for complex views - Image handling: Downscale images to display size
๐ More Questions Coming Soon!
This is a growing collection. Check back regularly for new questions on:
- SwiftUI architecture patterns
- Combine framework design
- Core Data optimization at scale
- Push notification architecture
- Background task scheduling
- And more!
Have suggestions? Email me with topics you'd like covered!
Share on
Twitter Facebook LinkedInโ Buy me a coffee! ๐
If you found this article helpful, consider buying me a coffee to support my work! ๐