Model Play Store Subscription Lifecycle as an Explicit State Machine
Last updated: November 29, 2026
Quick Overview
Model an app subscription that moves through trial, active, grace period, on hold, canceled, and expired states in response to billing events, rejecting illegal transitions and tolerating duplicate event delivery.
0
0
0 solved
Model an app subscription that moves through trial, active, grace period, on hold, canceled, and expired states in response to billing events, rejecting illegal transitions and tolerating duplicate event delivery.
Google Play Billing exposes exactly this kind of lifecycle with real-time notifications that can arrive late or twice. An onsite fundamentals interviewer uses it to see whether the candidate makes states and transitions explicit and data-driven, and handles idempotency and access rules cleanly.
What the Interviewer Expects
- Enumerates states and events and puts transitions in a table
- Rejects illegal transitions instead of silently ignoring them
- Deduplicates events by id so redelivery is harmless
- Separates the access decision from the state graph
- Keeps a history for debugging and support
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How do you handle events arriving out of order?
- How would you persist this so two servers processing events cannot corrupt state?
- How do you add a paused state without breaking existing logic?
- How would you test every transition and every illegal pair?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
- States: trial, active, grace, on hold, canceled (still paid through period end), expired.
- Events: payment outcomes, timeouts, user cancel, resubscribe, period end.
- Illegal events for the current...
High-Level Design
A dictionary maps (state, event) to the next state. Anything missing is illegal. That table is the whole policy: reviewable, diffable, and testable by enumeration. Subscription.handle checks the e...