Daily iOS
Concurrency

Async network client design

Using Swift Concurrency (async/await, actors), design the API of a network client that several screens use at the same time. It must never block the main thread, and it needs deduplication of identical requests, cancellation, and retries. Can you walk me through the interface and the internal concurrency structure?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

The interface is func fetch<T: Decodable>(_ endpoint: Endpoint) async throws -> T. Inside, an actor merges duplicate requests through a dictionary of in-flight Tasks, cancellation propagates the caller's Task cancellation to URLSession but only drops the request when the last waiter is gone, and retries use exponential backoff with a cancellation-aware sleep.

Share a question