AAA

"Explain how you would handle API integrations in a mobile application. Describe how you structure networking code, manage caching and retries, prevent duplicate requests, and keep the UI responsive when the network is slow or unavailable."
A clean API integration usually separates concerns into client, service, repository, and presentation layers. This makes request construction, response parsing, caching, and UI state management easier to test and maintain.
class UserRepository:
def __init__(self, api, cache):
self.api = api
self.cache = cache
Caching reduces latency, bandwidth usage, and repeated calls for the same resource. A strong answer should explain when cached data is acceptable, how freshness is tracked, and when stale data should be refreshed.
if key in cache and not cache[key].is_expired():
return cache[key].value
Transient failures such as timeouts or temporary server errors should be retried with exponential backoff. Permanent failures such as validation errors should not be retried and should be surfaced clearly to the UI.
delay = base * (2 ** attempt)
If multiple screens or components request the same resource at the same time, the app should avoid firing duplicate network calls. A common approach is to track in-flight requests by key and share the same pending result.
if request_key in inflight:
return inflight[request_key]
Mobile apps must handle intermittent connectivity gracefully. The UI should distinguish loading, success, stale cached data, empty state, and error state so users can continue interacting even when the network is unreliable.