skip to content

In a children's educational-video app's clip feed, how many upcoming clips would you preload, how much of each, and what cancels that on a flick?

level: middleimportance: must knowfreq 40%

answer

  1. start time against wasted bytes
  2. a few ahead, fewer behind
  3. the opening seconds, not the clip
  4. nearest first; cancel what leaves the window
  5. a capped cache, apart from downloads

basics

~20 s

Preload the opening seconds of the next two or three clips ahead and one behind, nearest first. A fast flick pauses new preloads and cancels requests for clips leaving that window, keeping bytes already in a capped disk cache.

solid answer

~40 s

Preloading trades start time for bytes the child may never watch, so I keep it shallow and ordered. Assume clips average 45 seconds and children swipe every few seconds: I'd fetch the opening two or three seconds, also capped in bytes, of the next two or three clips in the scroll direction and one behind, nearest first, and prepare a pooled player only for the very next clip. The bytes go into a byte-capped disk cache of opening seconds, kept apart from downloaded episodes. On a fast flick I stop issuing new preloads until the scroll slows, and cancel in-flight requests for clips that leave the window; whatever already reached disk stays. When the user's data-saving setting is on, preloading stops beyond the clip that is playing.

code

pseudocode · 14 lines
pseudocode
on scroll(position, direction, velocity):
  window = next_clips(position, direction, count = 3) + previous_clips(position, count = 1)
  for request in preloads_in_flight:
    if request.clip_id not in window:
      request.cancel()                 # bytes already on disk stay cached
  if velocity > fling_threshold:
    hold_new_preloads = true
    return
  hold_new_preloads = false
  if system.data_saving_on: return       # only the playing clip loads
  for clip in window.sorted_by(distance_from(position)):
    if opening_cache.covers(clip.id, opening_byte_cap): continue
    enqueue_preload(clip.id, max_bytes = opening_byte_cap, priority = distance_from(position))
  pool.prepare(next_clips(position, direction, count = 1))

go deeper

for a junior

Recall that preloading fetches only the opening seconds of the next few clips so they start quickly, and that a fast flick cancels preloads that are no longer useful.

for a middle

Explain the window, a few clips ahead in the scroll direction and one behind, nearest first, the byte cap per clip, and cancelling requests that leave the window while keeping what reached disk.

for a senior

Tie depth to measured watch time and swipe rate, keep the opening-seconds cache apart from downloads, and show the data-saving setting cutting preload back to the playing clip.

for a principal

Own preload depth as a policy tuned per device class and network from telemetry on start delay and wasted bytes, applied identically on every video surface.

## The trade preloading makes **Preloading** means fetching part of a clip before the child reaches it, so that when it becomes the active clip it can start from local bytes while the rest arrives. It is a **start-time** optimisation paid for in **bytes the child may never watch**. A feed that preloads nothing makes every swipe wait on the network; a feed that preloads everything burns the family's data plan on clips flicked past in a tenth of a second. The design is a bounded window with an order and a way to cancel. Scenario assumptions, stated so the numbers can be checked: clips last 20 to 90 seconds (45 on average), children often swipe after a few seconds, and many sessions run on a phone's cellular connection in the car. ## Depth: how many clips - **Ahead, in the scroll direction:** two or three clips. One is enough when the child watches each clip to the end, because the next clip has the whole current clip's duration to arrive; three helps a fast swiper. - **Behind:** one clip, because swiping back to the previous clip is common and cheap to cover. - **Ordered by distance:** the next clip first, then the one after. A request for the third clip must never delay the first. - **One prepared player:** only the very next clip gets a pooled player prepared; the others get bytes only, because players are scarce. None of these numbers is a standard. The right depth comes from the app's own telemetry, how long children stay on a clip and how often they swipe back, and is tuned per device class. ## Amount: how much of each clip Fetch the **opening seconds**, enough for the first moments of playback to start without waiting, and cap each preload **in bytes** as well as seconds so an unusually heavy clip cannot blow the budget. The remainder of the clip is fetched only when it becomes the active clip. Whole-clip preloading is the expensive mistake: most clips in a fast feed are abandoned within seconds, so most of those bytes are wasted. ## Priority and cancellation on a fast flick A **fling** is a fast swipe that carries the list past many items. The window moves faster than requests can finish. 1. While scroll velocity is above a fling threshold, **issue no new preloads**; the window is moving too fast for any of them to be useful. 2. For every **in-flight** preload whose clip has left the window, **cancel** the request. Cancelling stops further bytes; it does not delete what already arrived. 3. **Keep** bytes already written to the disk cache. A clip half-preloaded and then skipped may come back if the child swipes back. 4. When the scroll **settles**, recompute the window from the new position and issue preloads nearest first, skipping clips the cache already covers. 5. Priority stays below the **active clip's** own playback: a preload must never compete with the clip on screen. Generic list prefetch of rows and their data follows the same shape and is the list-rendering question's; here the object is the video bytes and the player. ## The disk cache for opening seconds Preloaded bytes land in a **disk cache**: a store of opening seconds keyed by clip id, with a byte cap and least-recently-used eviction. | | Opening-seconds cache | Downloaded episodes | |---|---|---| | Who asked for it | The app, speculatively | A parent, explicitly | | Size rule | Hard byte cap, assumed 100 MB here | What the parent chose, within free space | | Eviction | Least recently used, at any time | Never automatic; only by the parent, or at sign-out | | Where it lives | A folder the OS may purge when space runs low | Persistent app storage | | If it is lost | Fetch again from the network | The trip is ruined | The two must not share an eviction rule: a downloaded episode must never be evicted to make room for a speculative preload. ## When not to preload When the user's **data-saving setting** is on, preloading stops beyond the active clip; when the app leaves the foreground, in-flight preloads are cancelled. What each byte costs on the radio, and how a metered connection is detected, is the radio and data budget's question; this question keeps the window, the order and the cancellation.

  • Why keep preloaded bytes in a cache separate from downloaded episodes?
    They have opposite lifetimes. Opening seconds are speculative: a byte-capped, least-recently-used cache in a folder the OS may purge, refetched if lost. A downloaded episode is something a parent chose and is counting on in the car, so it must never be evicted to make room for a preload; it lives in persistent storage with its own accounting.
  • Children in this app usually watch each clip to the end; would you change the depth?
    Yes, toward one clip ahead. A child who watches 45 seconds gives the network the whole clip's duration to fetch the next one's opening, so a deeper window mostly fetches clips that may never be reached. A fast swiper is the opposite case. Let telemetry on watch time and swipe rate set the depth rather than fixing one number.

  • Preloading the next ten whole clips makes the feed faster at no real cost.
  • Cancelling a preload must also delete the bytes it already fetched.
  • Preloaded clips can share one eviction rule with downloaded episodes.
  • The preload window is the next few rows, whatever the scroll speed.
  • Every clip in the preload window should get its own prepared player.