Follow-up round: the user logs out offline on a shared phone
The setup
You designed a push notification SDK for Android apps. The SDK keeps one record for the device: the push address, the install ID, and the user it is linked to. Two people share one phone. The first person logs out, and the phone has no network at that moment. The second person logs in later.
The question
The interviewer asks: "The user logs out while the phone is offline. What does the SDK do with the device record?"
Stop here and answer out loud for one minute.
A weak reply
"I delete the push address, call the server to unlink the user, and wait for the answer." Offline, the call fails. The server still thinks the old user owns the phone, so the next person gets the old user's pushes. Waiting for the server before clearing local state can show one person's messages to another until the phone is online again.
A strong reply
- Clear the user on the device first, and add one to a local version. Then queue the unlink call, and clear the local inbox.
- An offline logout cannot leak. The server also unlinks the old user when a new user claims the same install ID.
- The client ignores any push whose user does not match the signed-in user. A push carries only a hint, and it names the user it is for, so the client can check.
- I never wait for the server before clearing local state.
The twist many people miss
The interviewer asks: "The app is killed right after logout, before the unlink call went out."
A good answer: the queued unlink is a row on disk. It is written in the same transaction that clears the user and adds one to the local version. At the next launch, the SDK sends that row first. The call carries the same install ID and version, so sending it twice changes nothing. An unlink kept only in memory is lost with the process, and the old user stays linked until someone else claims the install. One more detail: after logout, the unlink cannot use the old user's login. It goes out with a device credential tied to the install ID, or the SDK keeps the old token for that one call. If the server answers 401, I drop the row. The server relinks on the next claim.
Check yourself
- Did you clear local state before you called the server?
- Did you say why an offline logout does not leak to the next user?
- Did you put the unlink on disk, in the same transaction as the clear?
- Did you cover how the unlink is sent after the old login is gone?
Score your answer on the score sheet.
Go deeper
- Push SDK case: section 4.1 covers logout and the shared phone, and the failure table has a row for an unlink that runs after the login is gone.
- Build guide: the device record, the queued unlink and the calls.
- Idempotency keys: why sending the same call twice must change nothing.
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.