Build it. The database schema, API, code and platform limits for a stock ticker app are on a separate page: Build it: a stock ticker app on Android and iOS (16 min read).
How to read this. This page is a 45-minute round (the length I assume), in the order I would spend it. Wire formats, code and platform tables are in the build guide. The follow-up questions are my reconstruction of challenges that public prep material reports. They are not transcripts of real rounds.
TL;DR. My answer (the same on Android and iOS): the socket (a two-way connection that stays open) is the easy part. The hard part is deciding what the user may believe about a number. I stream only what is on screen, keep ticks (price updates) in memory, and show the latest value with its age. Sequence numbers (a counter for each symbol) repair gaps. A heartbeat (a regular ping), not silence, decides when prices are stale. On iOS, one actor owns the socket, and the app closes it when it goes to the background.
Patterns in this round.
- Repository (a quote repository is the way in, and ticks stay in memory because writing each one to the database costs too much)
- Observer (the screen collects a stream of prices)
- Coalescing (only the newest tick for each symbol is drawn)
More in design patterns in mobile rounds.
Free: one follow-up round a week. A short interview question with a weak and a strong answer, by email. You also get the cheat sheet.
1. Scope and constraints (minutes 0 to 4)
In short: Live means the rows on screen. Everything else gets a snapshot (current prices, fetched once).
A prompt I would expect: "Design the screen in a trading app that shows live prices." I ask five questions, with a default for each:
- How many symbols? Twelve on screen, fifty watched, thousands searchable.
- How live? Real time on screen, a snapshot elsewhere.
- Which screens? A watchlist and a detail screen with a chart.
- Client only? The client and the gateway contract, not the exchange side.
- Offline? Always online. Cached prices are marked stale (old, and maybe wrong).
| In scope | Out of scope | Parked until you ask |
|---|---|---|
| Live prices, watchlist and detail | Order entry | A widget or watch face |
| A chart with a live last point | News | Price alerts by push notification |
| Stale and closed states, background | Options, order books | Delayed versus real-time licences |
The phone is not one simple box:
| What the phone does | Requirement at risk | Deep dive |
|---|---|---|
| Kills the process | The first screen is honest | Data (2), structure (3) |
| Suspends the app, delays work | No stale number passes as live | Structure (3), link lies (4.2) |
| Stops the radio but keeps the socket open | The user is never lied to | Link lies (4.2) |
| Runs on a battery and a data plan | Live prices without draining either | Numbers (2), render (4.1) |
Your decision. Do you promise live prices for the whole symbol universe, or only for what the screen shows?
First idea, and why it fails. Subscribe to everything and let the UI pick the rows. Thousands of symbols exist and twelve are visible, so the radio and the data plan carry ticks nobody sees.
What I would say.
Say this. "Live means the rows the user can see. The watchlist is capped at fifty. It is the subscription set while it is on screen. Anything off screen gets one snapshot. Widgets, alerts and delayed licences are parked."
The follow-up question I expect:
"Traders want every watched symbol live, even off screen."
The cap is fifty. I still release a symbol when its screen goes away, because a hidden screen has no reader.
45-minute plan
| Minutes | Step | Shown by the end | Cut if short of time |
|---|---|---|---|
| 0 to 4 | Scope and constraints | Scope table, phone behaviors | Fewer questions |
| 4 to 14 | Data and contracts | Ticks in memory, contract, three numbers | The third number |
| 14 to 22 | Client structure | One stream owner, reference counts | One line per layer |
| 22 to 40 | Make the hard part work | Latest-wins render, heartbeat, snapshot | Accessibility question |
| 40 to 45 | Break it, ship it, roll it back | Top failures, the kill switch | Two failures and the flag |
2. Data and contracts (minutes 4 to 14)
In short: Ticks stay in memory. Only the watchlist and the last snapshot go to disk.
Your decision. Do live ticks go through the database like the rest of the app, or do they stay in memory?
First idea, and why it fails. Write every tick to Room (Android's database library), because the database is the source of truth (the one place with the final answer). On a busy open, that is hundreds of writes a second for values that are out of date within a second. The battery pays.
What I would say. Ticks live in a conflated in-memory map (it keeps only the newest value for each symbol). I save only the watchlist and the last snapshot for each symbol. This is a planned exception to the single source of truth rule. It fits short-lived data only.
The follow-up question I expect:
"Why a WebSocket and not server-sent events?"
It depends on whether the symbol set changes while the screen is open. It does, as rows scroll, so subscribe and unsubscribe messages use the same connection.
- For a fixed set, server-sent events (a one-way stream over HTTP) would be simpler.
- Polling (asking again and again) is out, because every answer is already old.
The follow-up question I expect:
"The process is killed. What is on screen at relaunch?"
The cached snapshot. Every row is marked stale, with its snapshot time, until a fresh one arrives.
The contract in four lines:
- Snapshot: the latest quotes for some symbols, with a sequence number and the market state.
- History: a time range and a number of points. The client adds live ticks to the last candle (one bar of the chart).
- Socket: subscribe and unsubscribe messages go up. A snapshot, then ticks, go down. Each tick has a per-symbol sequence number (
seq) and the server time. Market-state messages go down too. - Watchlist: one idempotent PUT per symbol (doing it twice has the same result as doing it once).
The seq is a promise from my gateway (the server between the exchange and the app): no missing numbers. An exchange feed does not promise this. Chat allows gaps (chat case).
These numbers are my own assumptions, not measurements:
| Assumption | Arithmetic | What it settles |
|---|---|---|
| 50 watched: 10 busy at 20 updates a second, 40 at 5; 60 frames a second | 200 + 200 is 400 messages a second, about 7 per frame | Render once per frame, not once per message; no disk write per tick |
| About 100 bytes per update; 12 visible rows capped at 4 a second | 400 x 100 B is 40 KB/s, about 144 MB an hour; 48 x 100 B is 4.8 KB/s, about 17 MB an hour | A visible-only set and a server rate cap beat any client trick |
| Ping every 10 s; dead after two missed pongs (replies) | Up to 10 s to the first ping, then 20 s: 20 to 30 s frozen | Stale depends on the heartbeat. A shorter interval (say 3 s) finds a dead link faster but costs battery. A longer one (say 60 s) leaves prices frozen for minutes. |
3. Client structure (minutes 14 to 22)
In short: One stream owner in the data layer, not in the ViewModel.
Your decision. Who owns the socket and the subscriptions? The ViewModel (the object that holds screen state), an object in the data layer, a WorkManager job, or a foreground service?
First idea, and why it fails. The ViewModel. It holds the screen state, so it opens the socket in viewModelScope. But Android clears a ViewModel when its screen leaves the back stack (ViewModel). Two screens with one symbol would open two sockets, each with its own gap bugs.
What I would say. One stream owner lives in the data layer, in its own scope. It starts on the first subscriber and stops when the app leaves the foreground. Subscriptions use reference counts (a count of screens for each symbol) and follow visibility.
I reject WorkManager. Android's background-work page points to it for tasks that must finish, and says that coroutine work stops when the app does (background tasks). A screen of prices is the second kind.
The follow-up question I expect:
"Keep it open in the background with a foreground service."
I would not. Android bars most background starts of foreground services (restrictions).
- - Android describes the type as immediate work that the user can see.
- A price screen that nobody looks at is neither.
- Alerts go by push notification.
More links
- Quote stream to Quote repository: state
- WebSocket to Quote stream: ticks
- Quote repository to Subscriptions: visible
The screen and the ViewModel are Android's UI layer. QuoteRepository is the entry to the data layer, with the REST client, stream owner and database behind it. I skip a domain layer until several ViewModels share logic (recommendations). Three rules:
- The UI never touches the socket; it collects state.
- Only the stream owner writes the in-memory book.
- The ViewModel gives the UI one immutable
uiState.
4. Make the hard part work (minutes 22 to 40)
In short: Render the latest value, never every tick. A heartbeat decides when prices are stale.
4.1 Render the latest, not every tick (minutes 22 to 31)
Your decision. A busy symbol ticks many times in one frame. Do you render every tick, sample on a timer, or apply every tick and render the latest?
First idea, and why it fails. A fixed sample(100) looks smooth, but its docs say the latest element is not sent if it does not fit the sampling window (sample). The last tick of a burst can vanish, and the row shows an old price until the next tick.
What I would say.
Say this. "I apply every tick to an in-memory map, and the screen reads the latest value. A StateFlow conflates, so a slow collector gets the newest value. I do not sample prices, because sampling can drop the last value of a burst. Every row shows its age."
The follow-up question I expect:
"Why not have the server send fewer ticks?"
I ask for both. A server cap saves bytes. Conflation protects the frame.
The follow-up question I expect:
"And a screen reader user?"
I announce only rare changes, such as "market closed", never ticks.
- Android's guidance says not to use live regions (areas that the screen reader speaks aloud) on content that updates often (semantics).
- On iOS, I keep the price as plain text. I post a VoiceOver announcement only for rare changes such as "market closed". The build guide covers the
updatesFrequentlytrait.
4.2 When the link lies (minutes 31 to 40)
Your decision. The connection drops, or it stays open and delivers nothing. After it recovers, do you replay what you missed, take a snapshot, or continue as before?
First idea, and why it fails. Trust the open socket, and replay the missed ticks after a reconnect. This fails for three reasons:
- A half-open connection (open, but silent) sends no close event. The frames just stop, so no reconnect ever starts.
- A captive portal (a login page before internet access) looks online. On Android it has the internet capability but is not validated (network state).
- Replay is wasted work when only the latest price matters.
What I would say.
Say this. "I ping every ten seconds. Two missed pongs mean the link is dead. I rebuild it, subscribe again to the active symbols, and take one snapshot for each. A sequence gap on a symbol means one snapshot request. I ignore its ticks until it arrives. A missed tick heals itself for a last price. A gap matters for the live candle, which is built from ticks."
I reject replay. I also reject polling as a second way to detect a dead link.
The follow-up question I expect:
"Chat replays after a drop. Why not here?"
A chat message is a separate fact, so losing one loses information. A price replaces the one before it. So the snapshot is my replay.
The follow-up question I expect:
"An illiquid symbol has not ticked for ten minutes. Is it stale?"
No. Stale is a fact about the connection, so it depends on the heartbeat. The row shows its own age. An old price on a healthy link is just old.
The follow-up question I expect: "The phone clock is two minutes wrong. What does the age say?"
- Age is now minus
serverTime. That mixes two clocks, so a wrong phone clock gives a wrong age, or a negative one. - I would store the gap between the phone clock and
serverTimewhen each snapshot arrives, and correct the age with it. Never show an age below zero. - After a relaunch, a cached row shows a date and time, such as "as of Tue 16:04", not "3 s ago". A relative age would be wrong for a snapshot saved hours ago.
- The cached market state is old too. I do not show "open" from the cache. I show it as last known until a fresh snapshot arrives.
4.3 Where iOS changes the design
The design is the same. Only the owner, the lifecycle and the buffering change. The Swift code is in the build guide.
Who owns the socket on iOS.
- One actor in the data layer owns the
URLSessionWebSocketTask, the in-memory book and the subscription counts. It is the same job as the Android stream owner. - Views never touch the socket. An
@Observable(orObservableObject) model on the main actor reads the newest state from the actor. - SwiftUI
onAppearandonDisappearacquire and release symbols. This is the iOS version of visibility-driven reference counts.
Buffering and reconnect.
AsyncStreambuffers without limit unless told otherwise, so I choose newest-only (.bufferingNewest(1)). Conflation is an explicit choice.- Apple documents no reconnect for
URLSessionWebSocketTask(Apple). I treat a failed receive as the end of the task, rebuild the connection and subscribe again myself. It does offer a ping (sendPing) for the heartbeat.
Background.
- iOS suspends an app soon after it goes to the background, and the socket stops being served. I close it when the scene reaches
.background, and I do not plan around a background socket. beginBackgroundTaskgives only a short window. I use it at most to send a clean unsubscribe.- Alerts go by APNs push notification. When the app returns, it reconnects, subscribes again and takes snapshots, as on Android.
5. Break it, ship it, roll it back (minutes 40 to 45)
In short: Every failure ends in an honest label and a fresh snapshot. The kill switch is a server flag.
| Failure | User sees | Data holds | Recovery |
|---|---|---|---|
| Half-open connection or captive portal | Prices gray and stale within about 30 s | The in-memory book, last seq per symbol | Rebuild, subscribe again, snapshot |
| Out-of-order delivery | Nothing; the late tick is dropped | Last seq per symbol | Drop the tick when seq is not newer |
| Background kill or throttle | Cached prices marked stale, then fresh ones | Watchlist and last snapshot | Reconnect, subscribe again, snapshot; alerts by push notification |
| User signs out or switches account while the socket is open | Never the other person's watchlist or prices | Watchlist and snapshots stored per user | Close the socket, drop the in-memory book and subscription counts, clear that user's cache, then connect again with the new token |
| Token expires while the socket is open | Prices gray out for a moment, then update | Watchlist and last seq per symbol | The socket closes with an auth error. Refresh the token, connect again, subscribe again, take one snapshot for each symbol |
| App killed after Create alert, then the user taps again | One alert, not two | The alert's clientId, saved before the first send | Reuse the same clientId after a relaunch or a retry |
| Old app version meets new server contract | The old format keeps working | Protocol version sent on subscribe | The gateway serves both formats |
| Market halted or closed | Close price and the state, no stale timer | Market state from the server | Stop expecting ticks |
Rows not linked to a source are my design choices. Sources are in Further reading.
Release facts:
- A Play staged rollout can be halted. Users who already have the build keep it (Play Console).
- An App Store phased release can be paused for up to 30 days (Apple). The page does not mention reverting installed copies.
- Old versions stay in the field, so the gateway serves the old tick format.
- The stream ships behind a server flag that tells clients to stop streaming and refresh snapshots slowly. This is my kill switch (a way to turn the feature off), and the only rollback that reaches installed apps.
- A watchlist schema change cannot be flagged off, so it ships one release before the code that needs it.
Say this. "I cannot recall a bad build, so the rollback is the flag plus a fixed build. I would watch time to first price, resync rate (new snapshots that repair data), reconnects per session and battery per session. Left out: orders, news."
6. Follow-ups that change a constraint
In short: Each follow-up changes one constraint. A strong answer says what breaks first.
These are practice prompts, not a claim about what interviewers ask.
- The market opens and 2,000 symbols move at once. Strong: name what fails first (parsing, the map, the main thread, the server's send buffer). Then add conflation, per-row state and a server rate cap. Weak: "scale the server."
- A home screen widget and a watch face. Strong: neither holds a socket. They show snapshots on a timeline. I read the platform refresh limits first. Weak: a socket in the widget.
- The watchlist and alerts are edited on a phone and a tablet. Strong: the server wins. The list PUT is idempotent. An alert POST carries a
clientId. A push notification is a hint that loads a snapshot. Weak: merge locally forever. - Some users are licensed for delayed prices. Strong: the server tags every quote and the client labels it. A token refresh on the live socket keeps the subscriptions. Weak: the client decides.
- After a release the resync rate doubles and battery complaints rise. Strong: switch the flag to snapshot mode, halt the rollout, and check the heartbeat interval and repeated subscribe storms. Weak: "roll back the release."
- The gateway changes the tick message and some users are on old builds. Strong: send a version on subscribe, serve both shapes, and retire the old one with a minimum-version rule. Weak: force an update.
7. What changes by level
In short: Levels differ in who raises the problem: the interviewer, the candidate, or the candidate with a rollout plan.
These levels are my reading of vendor and prep material (courses and books), not a company rubric.
- Mid-level: a WebSocket for prices, REST for history, decimal prices, limited UI updates. I want to hear: "Every price shows how old it is."
- Senior: visible-only subscriptions, conflation with a reason,
seqgaps repaired by snapshot, a heartbeat for the half-open link, and the socket closed in the background, all raised unasked. I want to hear: "Here is what the user may believe when the link lies." - Staff: which surfaces may hold a socket, one shared stream owner, what the kill switch turns off, feed cost, and metrics (staff guide). I want to hear: "Here is the guardrail that halts the release."
Common weak answers. Rendering every tick. Polling for prices. A
Doublefor money (it cannot store 0.1 exactly; use a decimal type). No stale or closed state. An hour on server fan-out. Naming a WebSocket library, but not saying what happens when it drops. No rollout plan. Treating a quiet symbol as a dead connection. These repeat across public prep material; they are not a dataset.
Staff answer: the decision and the rollout
Decision: one shared stream module owns the socket, the subscription counts and the seq checks. Each surface asks it for symbols and opens no connection. Alternative: one socket per surface. It is simpler to start, but it multiplies connections and gap bugs. Revisit trigger: a surface with a different freshness need, such as a widget or watch, where snapshots are enough.
Rollout: the stream goes behind the section 5 flag, then a staged release. Guardrail: the resync rate must not rise, and watchlist frame drops must not increase.
What I read and what is my view: I read the platform and store facts on official pages. The module split, metrics, rollback plan, numbers and level text are my opinion.
Test yourself
In short: Seven questions from this case. Answer each one out loud first, then open the answer.
1. Do you promise live prices for every symbol or only for what is on screen? Why?
Only the rows on screen. Subscribing to thousands of symbols to show twelve wastes the radio and the data plan. Off-screen symbols get one snapshot, and a symbol is released when its screen goes away.
2. Why do live ticks stay in memory and not go through the database?
On a busy open that would be hundreds of writes a second for values that are old within a second, and the battery pays. Only the watchlist and the last snapshot are saved, and cached rows are marked stale after a relaunch.
3. Why a WebSocket and not server-sent events?
The set of symbols changes while the screen is open, as rows scroll. Subscribe and unsubscribe messages can go up the same connection. For a fixed set, server-sent events would be simpler. Polling is out because every answer is already old.
4. Who owns the socket, and why not the ViewModel?
One stream owner in the data layer, in its own scope. A ViewModel is cleared when its screen leaves the back stack, and two screens with the same symbol would open two sockets with separate gap bugs. Subscriptions use reference counts and follow visibility.
5. Why not a foreground service to keep prices live in the background?
Android bars most background starts of foreground services, and the type is for immediate work the user can see. A price screen nobody looks at is not that. Alerts go by push notification.
6. About 400 messages a second arrive for 50 watched symbols. How often do you draw?
Once per frame, and only the latest value for each symbol, not once per message. That is about 7 messages per frame. A visible-only set and a server rate cap save more data than any client trick.
7. The app goes to the background on iOS. What happens to the socket?
iOS suspends the app soon after, and the socket stops being served. So I close it when the scene reaches background and do not plan around a background socket. Alerts go by APNs push. When the app returns, it reconnects, subscribes again and takes snapshots.
Further reading (official docs)
- Build it: a live stock ticker on Android and iOS: money types, wire formats, code and platform limits for this case
- Background tasks overview (Android)
- Foreground service restrictions on background starts (Android)
- Reading network state (Android)
- Doze and App Standby (Android)
- Architecture recommendations (Android)
- Flow.sample (kotlinx.coroutines)
- URLSessionWebSocketTask (Apple)
- Mobile system design repository (weeeBox, GitHub): a reference I read. It compares polling, long polling, server-sent events, WebSocket and push. It lists a stock ticker as a server-sent events example
- Grokking the Modern Mobile System Design Interview (DesignGurus): a course I read in part. I saw only the intro of its stock ticker lesson, which frames which updates may be dropped
Words on this page (21)
- Captive portal
- A login page that a Wi-Fi network shows before it gives access to the internet. The phone looks online, but requests fail.
- Conflation
- Joining many updates into one. The app keeps only the newest value for each item.
- Coroutine
- A light background task in Kotlin. It can pause and continue later without blocking a thread.
- Doze
- The deep-sleep mode of an idle Android phone. It pauses network access and delays background work.
- Foreground service
- An Android service that shows a notification while it works. The system is less likely to stop it.
- Heartbeat
- A small message that is sent on a timer. If the messages stop, the app knows the connection is broken.
- Idempotent
- Doing it twice has the same result as doing it once. This makes a retry safe.
- Kill switch
- A remote flag that turns a feature off at once. It is the one rollback that reaches apps that are already installed.
- Main thread
- The thread that draws the screen. If slow work runs on it, the screen freezes.
- Polling
- Asking the server again and again if there is news. It costs battery and data.
- Repository
- The class that reads and writes data for the rest of the app. It hides whether the data comes from the network or the database.
- Rollback
- Going back to the old behavior after a problem. A build on a user's phone cannot be taken back, so teams use a kill switch.
- Room
- Android's library for the database on the phone. You use a DAO to read and write the data.
- Sequence number
- A number that grows by one with each message. It shows the order, and it shows a gap when a number is missing.
- Snapshot
- A copy of the data as it was at one moment. It is not a list of changes.
- Source of truth
- The one copy of the data that the app trusts. In these cases it is the database on the phone, and the screen only reads it.
- Staged rollout
- A release to a growing share of users, not to everyone at once. It limits the harm of a bad release.
- Stale data
- Saved data that may be out of date. The app should show how old it is, or refresh it.
- ViewModel
- A class that holds the state of one screen. It survives a screen rotation.
- WebSocket
- A two-way connection that stays open. The server can send data to the app at any time.
- WorkManager
- Android's tool for background work that must run later. The work survives when the app closes or the phone restarts.
Verification notes (last reviewed 14 Oct 2026)
What I checked on official pages (14 Oct 2026).
- Android: a ViewModel is cleared when its screen leaves the back stack.
- Android: coroutine work stops when the app leaves the foreground. Foreground services are for immediate work the user can see, and most cannot start from the background on Android 12 and higher.
- Android: a captive-portal network has the internet capability but is not validated. Doze suspends network access except in maintenance windows.
- kotlinx.coroutines:
samplemay not send the latest element.StateFlowconflates. - Compose: avoid live regions on content that updates often.
- Play: halting a staged rollout leaves the update on devices that already have it.
- Apple: phased release can be paused for up to 30 days, and the page does not mention reverting installed copies.
- Apple:
URLSessionWebSocketTaskhas a ping method and documents no reconnect.AsyncStreamhas an unbounded default buffer.
What is my own design or opinion.
- The
seqcontract is my gateway assumption. Exchange feeds do not promise it. - The stale-versus-quiet-symbol rule, the numbers, the failure rows, the scripts and the level text are my reasoning, not documented rules.
- The follow-up questions are my reconstruction from public prep material, not transcripts of real rounds.
What I did not verify.
- OkHttp behavior is described in the build guide from memory of its docs.
- No iOS engineer has reviewed the iOS parts.
Questions or corrections?
Add them to the discussion thread for this case on GitHub. To post, you need a free GitHub account. What you write there is public and follows GitHub's terms. Good answers are added to this page.
Keep reading
Get the free one-page cheat sheet
One page: the five steps, a 45-minute time plan and two checklists. Print it or keep it on your phone.
We email you the cheat sheet after you confirm your address. You can also open it now from the Start here page. You also get a short email each week with a follow-up round, and a note when a new case is published. Unsubscribe any time. Privacy.