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:

  1. Architecture: MVVM with Coordinator pattern
  2. Data Layer: Repository pattern with caching
  3. Image Loading: SDWebImage or custom solution with NSCache
  4. Prefetching: UITableViewDataSourcePrefetching
  5. Video: AVPlayer pool, reuse strategy
  6. Pagination: Cursor-based or offset-based
  7. Offline: Core Data or Realm for persistence

๐Ÿ’ก Pro Tips:

  • Discuss trade-offs: memory vs network vs UX
  • Mention UICollectionView vs UITableView 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:

  1. Transport Layer: URLSession WebSocket with reconnection logic
  2. Message Queue: Pending, sent, delivered, read states
  3. Local Storage: Core Data with background contexts
  4. Media Upload: Background URLSession with progress tracking
  5. 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:

  1. Measure: Use Instruments (Time Profiler, System Trace)
  2. 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:

  1. Move to background: Image decoding, text sizing, layout calculations
  2. Optimize layers: Reduce layer count, avoid offscreen rendering
  3. Cell optimization: Reuse cells properly, pre-calculate heights
  4. Rendering: Use CALayer directly for complex views
  5. 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!