A music-streaming app sets up eight third-party SDKs before its first frame; how would you stage their start-up, and which must start first?
answer
- not everything needs the first frame
- crash reporting before anything can crash
- after the first frame, or on first use
- a seam that builds on first call
- cached config, never a blocking fetch
basics
~20 sGive each SDK the latest phase that still works: crash reporting before anything else; analytics, ads and attribution after the first frame; payments, support chat and casting on first use, each behind a seam built on first call.
solid answer
~50 sFirst measure what each SDK costs on a low-end phone, then give each the latest phase that still works. **Before the first frame**: crash reporting, so a crash during launch is still recorded, plus only what the first screen needs, with remote configuration read from values cached last session rather than fetched. **After the first frame, when the app is idle**: analytics, ads and install attribution, since nothing on the first screen depends on them. **On first use**: payments when the paywall opens, support chat when help opens, casting when the speaker picker opens. Each deferred SDK sits behind an interface the app owns whose implementation is built on its first call, so no feature can start it at launch by accident. Deferral is not free of limits: on one platform every linked third-party library still adds load time before any app code runs.
code
pseudocode · 28 linesstartup_plan = [
{ sdk: "crash_reporting", phase: "before_first_frame" },
{ sdk: "remote_config", phase: "before_first_frame", mode: "read_cache_only" },
{ sdk: "analytics", phase: "after_first_frame" },
{ sdk: "ads", phase: "after_first_frame" },
{ sdk: "install_attribution", phase: "after_first_frame" },
{ sdk: "payments", phase: "first_use" },
{ sdk: "support_chat", phase: "first_use" },
{ sdk: "casting", phase: "first_use" }
]
on process_start:
for item in startup_plan where item.phase == "before_first_frame":
timed(item.sdk, start(item))
draw_first_screen(last_session_from_disk)
on first_frame_drawn:
when main_thread_idle:
for item in startup_plan where item.phase == "after_first_frame":
timed(item.sdk, start(item))
remote_config.refresh_in_background()
seam support:
chat = none
open(conversation):
if chat == none:
chat = timed("support_chat", start_support_chat())
chat.open(conversation)go deeper
Remember the three phases (before the first frame, after it, on first use) and that crash reporting is the one SDK that genuinely belongs first.
Explain how to place each SDK: measure its set-up cold on a low-end phone, choose the latest phase that still works, and hide deferred SDKs behind an app-owned seam built on first call.
Show the limits: library loading and self-starting code that deferral cannot touch, background threads that still compete for CPU, main-thread-only SDKs, and why a blocking config fetch is the worst entry on the path.
Turn staging into a rule many teams follow: one start-up registry where every SDK declares its phase, a review for anything added before the first frame, and field timing per phase.
## Measure before you move anything The **critical path** of a launch is the work the first frame waits for. SDKs land on it because most of them ask to be set up "as early as possible", and eight such requests add up. Before reordering anything, time each SDK's set-up on a **low-end device, cold, release build**, and note which thread it runs on, whether it reads disk, and whether it touches the network. One platform's launch guidance names the usual culprits: heavy work in the app's start-up code, global objects initialised eagerly, and disk reads or deserialisation during the bottleneck. Its fix is lazy initialisation: create only what is immediately needed. ## Give every SDK a phase The rule is **the latest phase that still works**. Three phases are enough for most apps: 1. **Before the first frame**: only what must exist for the first screen to be drawn correctly, or for a failure during launch to be seen. 2. **After the first frame, at idle**: anything the first screen does not use, started once the screen is drawn and the main thread is free. 3. **On first use**: anything tied to a feature the user may never open in this session. | SDK | First genuinely needed | Phase | Why | |---|---|---|---| | Crash reporting | before any code can crash | before first frame | a launch crash before it starts is never recorded | | Remote configuration | first screen reads flags | before first frame, **cache only** | read last session's values; the network refresh runs later | | Analytics | first event | after first frame | events raised earlier wait in a small app-owned queue | | Ads | first ad slot | after first frame | no ad is on the first screen | | Install attribution | during the first session | after first frame | it must run, but not before the user sees anything | | Payments | paywall opens | first use | most launches never open it | | Support chat | help screen opens | first use | rarely used | | Casting | speaker picker opens | first use, or idle if a cast button needs discovery | discovery searches the local network | The casting row is a real trade-off: if the design shows a cast button only when speakers are present, discovery must run in the background after the first frame; if the button is always shown, discovery can wait for a tap. ## Crash reporting goes first, and stays small Crash reporting is the one SDK with a hard reason to start before everything else: a crash in the first second, perhaps inside another SDK's set-up, is invisible if the reporter is not yet installed. That privilege comes with a duty: its own set-up must be cheap, with no network call and no large disk read on the main thread. Anything it uploads can wait. ## Lazy creation behind a seam Deferring by convention ("please don't call the chat SDK at launch") decays as teams add features. A **seam** makes it structural: - The app defines its own small interface, such as `support.open(conversation)`, and features depend only on that. - The real SDK is constructed inside the implementation on the **first call**, and its set-up time is logged. - No launch code holds a reference to the SDK itself, so a new feature cannot start it eagerly without changing the seam, which is a reviewable change. - The seam is also where a kill switch or a consent check would sit, though how those are decided belongs to other parts of the design. ## What deferral does not fix - **Loading cost.** On one platform, each additional third-party library the app loads adds to launch time before any of the app's code runs; deferring set-up does not remove it, and only dropping or merging libraries does. - **Self-starting code.** Some libraries arrange to run set-up code at process start without the app calling them; one platform runs code a library marks for load time before the app's own entry point, and the other's guidance flags start-up through such automatically created components. Audit for these. - **Background is not free.** Moving set-up to a background thread before the first frame still competes for CPU and disk on a phone with few cores, and anything the first screen waits for is still on the path. - **Main-thread-only SDKs.** Some must be set up on the main thread; post them after the first frame, so they cost a brief pause rather than a late first frame. A staged start-up holds only if it is measured: time each phase in the field, so a new SDK added to phase 1 shows up as a number, not a mystery.
- Install attribution must report the first launch after install; does that force it before the first frame?No. It must run during the first session, not before the first frame. Record the first-launch fact and its time cheaply at start-up, then start the SDK after the first frame. If the user leaves within a second, the next launch sees the install was never reported and catches up.
- Product wants the remote configuration fetched before the home screen so new playlists appear instantly; what do you answer?The first frame uses the values cached last session, or the defaults built into the app; the fetch runs in the background and its values take effect at a point the configuration design chooses. Blocking the first frame on it puts a network round-trip, and on a weak signal a full timeout, on every cold start.
- An SDK insists on main-thread set-up; can it still be deferred?Yes: deferral is about when, not which thread. Post its set-up to the main thread after the first frame is drawn, so it costs a brief pause while the user looks at content rather than a late first frame. Measure that pause too, since a long one becomes a visible stall.
- Every SDK must be initialised at process start or it will not work.
- Crash reporting can wait until after the first frame like analytics.
- Setting SDKs up on background threads before the first frame makes them free.
- Fetching remote configuration before the first frame costs only a few milliseconds.
- Deferring an SDK's set-up removes all of its launch cost.