Home / image caching system design iOS
Mobile system design
Image caching system design iOS
Designing an image cache is a common feed-app prompt. It tests memory awareness, concurrency, and how you handle reuse and failure.
The pipeline
Design a two-tier cache: a fast in-memory cache such as NSCache for decoded images and a disk cache for persistence across launches. On request, check memory, then disk, then network, decoding and downsampling to the display size before caching. Coalesce duplicate requests for the same URL so you do not fetch it twice.
The constraints that matter
Downsample large images to the view size to avoid huge memory spikes, and let the memory cache evict under pressure, which NSCache does automatically. Cancel an in-flight load when its cell is reused so a stale image cannot appear, and handle failures with retries and a placeholder. Naming memory pressure and reuse cancellation unprompted signals real experience.
Go deeper than a summary
Share Your Screen works topics like this through in full: 75 solved Swift problems with tests, 9 real case studies, and 7 annotated mock interviews, so you rehearse the live round instead of just reading about it.
Frequently asked
Why use NSCache instead of a dictionary for images?
NSCache is thread safe and automatically evicts entries under memory pressure, which a plain dictionary does not, preventing memory-related crashes.
How do you avoid the wrong image in a reused cell?
Cancel the previous cell's image request on reuse and verify the target before applying, so a late response cannot overwrite the current content.