skip to content

Shapes of a Window

Fixed intervals, overlapping intervals and gaps in the data itself define groups differently, and one record can land in several results at once.

on this pageshow

questions

5

A grouping uses ten-minute spans restarted every two minutes. How many groups does one record belong to, and why?

level: juniorimportance: must knowfreq 70%

answer

  1. the spans overlap on purpose
  2. two numbers: length and step
  3. how many started within one length
  4. length divided by step
  5. counted once per group, so never sum

basics

~10 s

Five. A span of fixed length restarted every step shorter than that length overlaps its neighbours, so a record's moment falls inside length-divided-by-step spans at once and is counted in every one of them.

solid answer

~40 s

Five, because the ten-minute length divided by the two-minute restart step is five. A new span starts every two minutes and each runs for ten, so at any moment five spans are open, and a record's moment lies inside all five of them — it is counted five times, once per group. Two consequences follow directly. The job emits **five times as many results** as back-to-back ten-minute spans over the same input. And the results are **not a partition**: adding the five totals up reconstructs nothing, it counts each record once per group it fell into. Whether a runtime physically assigns the record to five groups or keeps partial values that are combined on emission varies between engines, and changes neither number.

go deeper

for a junior

Do the division out loud: length divided by restart step is how many groups cover any moment, so ten over two is five. Then say the record is counted in each of them.

for a middle

Carry it further than the number. The same definition multiplies output rows by the same factor, and it is why these results are not a partition of the input and cannot be added up.

for a senior

Show what it obliges downstream: a compound identity of grouping key plus span start, and consecutive results that share most of their records, so one underlying event scores against many groups.

for a principal

Ask whether the fan-out is bought deliberately. A refresh every minute over an hour is sixty times the rows and sixty times the storage for a smoothness nobody asked for; the step is a cost decision, not a detail.

## The definition and the arithmetic An overlapping grouping is stated with two numbers: a **length** — how much of the timeline one group covers — and a **restart step** — how often a new group begins. When the step is shorter than the length, a new group starts before the previous one has ended, so several are open at once. With a ten-minute length and a two-minute step, a new group opens at every even minute and each stays open for ten, so at any instant five groups are live. A record's moment lies inside every group that started within one length before it. That is the whole derivation: - groups open at each multiple of the step; - a group starting at time `s` covers moments from `s` up to `s + length`; - so the groups containing moment `t` are those with `t - length < s <= t`, and there are **length divided by step** of them. Ten divided by two is five. Fifteen-minute spans restarted every five minutes give three. Sixty-minute spans restarted every minute give sixty. ## When the ratio is not a whole number If the step does not divide the length evenly, the count is that ratio rounded up or down, and **it is not the same for every record**. With a ten-minute length and a three-minute step, some moments sit inside four groups and some inside three. Nothing is broken, but any explanation that leans on a single fan-out number is only true when the step divides the length. Requirements are usually written with a step that divides the length precisely so the fan-out is uniform. Two degenerate cases are worth holding: | step against length | overlap | a record belongs to | |---|---|---| | step shorter than length | length minus step | length divided by step groups | | step equal to length | none | exactly one group | | step longer than length | negative, so gaps appear | one group, or none if its moment lands in a gap | ## What the fan-out costs downstream The fan-out is not an internal detail; it is visible to everyone who reads the output. 1. **Output volume.** For the same input and the same length, an overlapping grouping produces as many results per grouping key as the fan-out factor. A sixty-minute figure refreshed every minute is sixty rows per key per hour, not one. 2. **Results cannot be added.** Each record is inside several groups, so summing the group totals multiplies the true figure by roughly the fan-out. A daily total must be built from a non-overlapping shape, or by taking only every nth overlapping group so the ones taken do not overlap each other. 3. **A row needs a compound identity.** Because a grouping key now has several live results at once, a result row is identified by the grouping key **together with the span's start moment**, never by the key alone. 4. **Neighbouring results are highly correlated.** Consecutive overlapping results share all but one step's worth of records, so a threshold evaluated on each of them will alert repeatedly for one underlying event. What to do about that belongs to whoever owns alerting, but the shape is what causes it. ## What is an implementation choice and what is not The fan-out count is a property of the definition and is the same everywhere. How a runtime *achieves* it is not: - some assign each arriving record to every group that covers it, so the record is touched once per group; - some maintain one partial value per step-sized slice and combine the relevant slices when a group is handed downstream, so the record is touched once; - a runtime that advances by collecting arrivals for a short span and running one finite job over the set cannot restart a group more often than that span; - the oldest model in this class, a finite two-phase pass materialising its intermediate result to disk, does not keep overlapping groups open at all — the equivalent is re-running the pass once per span over a finite slice of history. What this shape costs in memory, and whether the aggregate can be kept as one mergeable value per group or needs every record, is a neighbouring subject and should be answered there rather than guessed at here. ## Saying it cleanly in an interview Give the number, the derivation and one consequence: *five, because the length divided by the step is five; the same record is counted in all five, so these results are five times as many rows and must never be summed into a total.* That answer survives being asked about any engine, because none of it depends on one.

  • What happens to the fan-out if the restart step does not divide the length evenly?
    It stops being uniform. With a ten-minute length and a three-minute step, some moments fall inside four groups and others inside three, because the count is the ratio rounded either way depending on where the moment sits. Nothing breaks, but any claim that rests on a single fan-out number is only true when the step divides the length.
  • How can a correct daily total be recovered from an overlapping definition?
    Take only groups that do not overlap each other — every fifth span when the fan-out is five — or compute the total from a separate non-overlapping grouping. Adding all the overlapping results is wrong by roughly the fan-out factor, and no correction applied after the fact recovers it, because the overlap is in the definition, not in the data.

A parade filmed by a camera whose shutter stays open for ten seconds and fires again every two seconds. Each marcher appears in five frames. Counting marchers frame by frame and adding the frames says five parades went past, when only one did.

saying these in an interview costs you the question

  • Says a record belongs to one group regardless of the restart step
  • Sums overlapping group totals into a daily figure
  • Thinks overlapping spans emit as many results as non-overlapping ones
  • Reads the two-minute step as a two-minute span
  • Claims every engine must physically copy the record into each group
open as a page

Over an endless input, what three ways can a grouping boundary be defined, and what sets each group's extent?

level: juniorimportance: must knowfreq 76%

basics

~20 s

Three shapes: back-to-back spans of equal length, where a record lands in exactly one group; fixed-length spans restarted every shorter step, where a record lands in several at once; and groups the data itself closes after a stated quiet period.

open as a page

A per-user grouping closes after five quiet minutes. What sets each group's length, and what can keep one open indefinitely?

level: middleimportance: should knowfreq 58%

basics

~20 s

The arrivals set it. The group stays open for one user while records keep coming and closes only once five minutes pass with none, so its length is data rather than definition — and a user who never pauses for five minutes keeps a group open forever.

open as a page

A stakeholder asks for an alert on errors in the last five minutes. What must be pinned down before it can be computed?

level: middleimportance: should knowfreq 60%

basics

~20 s

The phrase fixes only a length. Still undefined: whether the five minutes advances continuously or resets on a grid, how often it is recomputed, what groups the records together, which moment it is measured against, and what counts as an error.

open as a page

A report sums per-group results into daily totals. Which grouping shapes may it sum safely, and which will double count?

level: seniorimportance: should knowfreq 48%

basics

~20 s

Only shapes whose groups partition the input may be summed: back-to-back equal spans globally, and gap-closed groups per key. Overlapping spans cover each record length-divided-by-step times, so summing them inflates the total by that factor.

open as a page