Design a localized usage-limit API and Android Compose Snackbar with model identity, retry timing, and an upgrade action. Explain rapid duplicate errors, queued displays, coroutine cancellation, and recomposition-safe event handling.
Design a Localized Usage-Limit Response and Compose Snackbar
Company: OpenAI
Role: Android Engineer
Category: Software Engineering Fundamentals
Difficulty: hard
Interview Round: Technical Screen
In an Android chat-app exercise, a message request can fail because the selected model has reached its usage limit. Design the API error data and Compose client behavior so a Snackbar identifies the model, offers an "Upgrade to Plus" link or action, and tells the user to retry after the indicated number of hours.
Support multiple languages and explain what happens if two messages produce limit errors in quick succession. This is a design scenario, not a statement of any live product's quota or upgrade policy.
### Constraints & Assumptions
- The server determines whether the usage limit has been reached.
- The client must render localized text and an actionable upgrade destination.
- Distinguish a retry estimate from a guarantee that a later request will succeed.
### Clarifying Questions to Ask
- Does the response supply a retry duration, reset instant, or both, and how is clock skew handled?
- Should repeated errors for the same model/reset window be coalesced?
- Must the upgrade affordance be an inline link or is the Snackbar action suitable?
### Part 1 — Define the Error Contract
Specify structured fields the client needs without forcing it to parse an English sentence.
#### What This Part Should Cover
- Stable error identity, affected model, retry information, and upgrade action.
- Localization responsibility and safe navigation.
- Unknown-field or missing-data fallback behavior.
### Part 2 — Show the Snackbar in Compose
Explain the host state, coroutine/effect trigger, rapid error handling, and action callback.
#### What This Part Should Cover
- A stable Snackbar host and lifecycle-aware event handling.
- Single-display/queue behavior and deliberate deduplication policy.
- Prevention of repeated side effects during recomposition.
```hint
Calling a suspending display operation directly while a composable renders is not the same as handling a new error event.
```
### What a Strong Answer Covers
Connect a machine-readable server error to localized, accessible UI behavior. Explain both the two-request race and the lifecycle of the coroutine that displays or queues the Snackbar.
### Follow-up Questions
- What if the screen leaves the composition while a Snackbar is queued?
- How would a language change affect an error still waiting to be shown?
- How would you avoid showing stale retry information?
Overview: Design a localized usage-limit API and Android Compose Snackbar with model identity, retry timing, and an upgrade action. Explain rapid duplicate errors, queued displays, coroutine cancellation, and recomposition-safe event handling.
In an Android chat-app exercise, a message request can fail because the selected model has reached its usage limit. Design the API error data and Compose client behavior so a Snackbar identifies the model, offers an "Upgrade to Plus" link or action, and tells the user to retry after the indicated number of hours.
Support multiple languages and explain what happens if two messages produce limit errors in quick succession. This is a design scenario, not a statement of any live product's quota or upgrade policy.
Constraints & Assumptions
The server determines whether the usage limit has been reached.
The client must render localized text and an actionable upgrade destination.
Distinguish a retry estimate from a guarantee that a later request will succeed.
Clarifying Questions to Ask Guidance
Does the response supply a retry duration, reset instant, or both, and how is clock skew handled?
Should repeated errors for the same model/reset window be coalesced?
Must the upgrade affordance be an inline link or is the Snackbar action suitable?
Part 1 — Define the Error Contract
Specify structured fields the client needs without forcing it to parse an English sentence.
What This Part Should Cover Guidance
Stable error identity, affected model, retry information, and upgrade action.
Localization responsibility and safe navigation.
Unknown-field or missing-data fallback behavior.
Part 2 — Show the Snackbar in Compose
Explain the host state, coroutine/effect trigger, rapid error handling, and action callback.
What This Part Should Cover Guidance
A stable Snackbar host and lifecycle-aware event handling.
Single-display/queue behavior and deliberate deduplication policy.
Prevention of repeated side effects during recomposition.
What a Strong Answer Covers Guidance
Connect a machine-readable server error to localized, accessible UI behavior. Explain both the two-request race and the lifecycle of the coroutine that displays or queues the Snackbar.
Follow-up Questions Guidance
What if the screen leaves the composition while a Snackbar is queued?
How would a language change affect an error still waiting to be shown?
How would you avoid showing stale retry information?