Mobile Design Rounds
Follow-up roundAndroid3 min read

Follow-up round: the token expires while the user uploads

. Drafted with AI assistance, then edited by Manuel. Based on the photo backup case. Android and WorkManager only.

The setup

You designed photo backup. A big video is uploading in a WorkManager job. The file is split into blocks, and the server has told the app which blocks it still lacks. The upload is about halfway when the access token expires.

The question

The interviewer asks: "The access token expires in the middle of the upload. What does the app do?"

Stop here and answer out loud for one minute.

A weak reply

"The request fails with a 401, so I mark the upload as failed and send the user to the login screen." The user comes back to a failed backup for a problem they did not cause. Most 401s are not a logout. They only mean the short-lived access token ran out.

A strong reply

  • A 401 on one block does not fail the upload. That block was not stored, so I refresh the token once and send that same block again.
  • Several blocks can fail at the same moment. Only one refresh call runs, and the other requests wait for its result. Many refreshes at once can look like a stolen token to a server that rotates refresh tokens. The token refresh explorer shows this.
  • If the refresh itself is refused (the server says the refresh token is no longer valid), the upload pauses with a reason. The blocks still missing stay in the missing list. After the user logs in, the job asks the server for the list again and continues. It does not start over.
  • A timeout or a 5xx on the refresh call is different. That does not log the user out. I keep the tokens and try again later.

The twist many people miss

The interviewer asks: "The user logs in again, but with a different account."

A good answer: the paused upload belongs to the old account. Every item, block and session row stores the account it was made for, and the uploader checks the current account before each block. So it never sends one account's photos to another account. I would ask the user: keep the queue for the old account, or delete it.

Check yourself

  • Did you say a 401 is not a failed upload, and that only that block is retried?
  • Did you say only one refresh runs when many requests fail together?
  • Did you say what happens to the progress when the refresh fails?
  • Did you cover the login with another account?

Score your answer on the score sheet.

Go deeper

  • Photo backup case: the failure table has a row for a credential that expires mid-operation, and section 4 covers the account check.
  • Token refresh explorer: change one setting and see how many refresh calls the app makes.
  • Build guide: the schema and calls for the upload.

All follow-up rounds

Get the follow-up round by email

One short email each week. The cheat sheet comes with the first one.

You confirm your address first. Unsubscribe any time. Privacy.