Daily iOS
Networking

Token refresh concurrency

Five API calls go out at once when a screen appears, the access token has expired, and all five get a 401. Right now each request calls refresh on its own, so the server invalidates the refresh token and the user gets logged out. How would you fix it?

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

Run the refresh in one place (an actor) as a single in-flight Task so concurrent 401s await the same refresh, then retry the original request once. Refreshing ahead of time based on the expiry is better still.

Share a question