A per-user grouping closes after five quiet minutes. What sets each group's length, and what can keep one open indefinitely?
answer
- no length in the definition
- activity, then a stated absence
- per key, unequal, unknown until closed
- a busy key never pauses
- cap it with a maximum extent
basics
~20 sThe 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.
solid answer
~50 sThis shape states a **quiet period**, not a length. A group opens for one grouping key when a record for that key arrives, stays open while records keep arriving, and is declared finished once the stated quiet period elapses with nothing for that key. Its extent is therefore a property of the data: unknown when the job is written, unknown while the group runs, and different for every key — one user's group lasts forty seconds and another's four hours. Two consequences matter in an interview. A key whose arrivals never pause for longer than the quiet period holds a group open **indefinitely**, which is why a stated maximum extent is usually layered on top so the group is cut and a new one starts. And a record arriving inside what looked like a quiet stretch can **bridge** two groups for that key into one, because the stretch turns out never to have been quiet for the full period. Whether a runtime supports that bridging varies.
go deeper
Say what opens and closes the group: an arrival opens it, further arrivals extend it, and a stated stretch with no arrivals for that key closes it. The length is whatever the data made it.
Explain the consequences of a data-set extent: unequal per-key lengths, nothing landing on a reporting grid, and rates that are meaningless unless the extent travels with the result.
Bring up the key that never goes quiet and name the ceiling that fixes it, then say what the ceiling costs consumers: one long visit arrives as two rows they have to stitch.
Question whether the subject really is activity-bounded. If the business will never accept a visit split at a ceiling and will never accept an open group either, the requirement is contradictory and should be settled before any shape is chosen.
## The mechanism The first two grouping shapes state an extent and let the data fall into it. This one inverts that: it states only **how much quiet ends a group**, and lets the data decide the extent. For one grouping key — a user, a device, a vehicle — the rule runs: 1. a record arrives for the key and no group is open, so a group opens; 2. further records for that key extend it, each pushing the deadline out by the quiet period; 3. once the quiet period elapses with no record for that key, the group is declared finished and its value can be handed downstream. The shape exists because some real subjects have no clock-aligned boundary at all. A visit, a trip, a support conversation and a debugging session are each defined by activity followed by absence, and an equal-span grouping would cut one of them across three intervals and merge two of them into one. ## The extent is a property of the data This is the single fact the shape turns on, and everything awkward about it follows: - **You cannot state the extent in advance.** Not when writing the job, not while the group is open. It is known when the group closes, and not before. - **Extents are per key and unequal.** Two groups closing at the same moment may have covered nine seconds and nine hours. - **Nothing lands on a grid.** Results from equal spans line up for every key and can be laid straight onto a reporting calendar; these cannot, so a report over them has to re-bucket by, for example, the moment each group started. - **A rate is not comparable across groups.** Events divided by extent means one thing for a nine-second group and another for a nine-hour one; the extent has to travel with the result or the number is misread. ## Bridging: two groups can turn out to be one Records do not always arrive in the order their moments describe. Suppose the quiet period is five minutes, a group ran to 10:02, another opened at 10:09, and a record whose moment is 10:05 now turns up. - Read strictly, the stretch from 10:02 to 10:09 was never five minutes of quiet, so the two groups are one group running from before 10:02 to after 10:09. - A runtime that supports **merging** will bridge them, and what was two results becomes one — which means a consumer may see a correction rather than two independent rows. - A runtime that does not support merging leaves them as two, and the visit is reported as two visits. Engines genuinely differ here, so the honest interview answer names the possibility and says the behaviour depends on whether the grouping supports merging. How disorder is detected and how a record is judged to have arrived after its group was finished are separate subjects; what belongs here is only that the extent may be revised. ## The key that never goes quiet The unbounded case is the one interviewers probe. An automated client, a stuck retry loop or a genuinely busy account may emit records faster than the quiet period forever. Its group never closes, it never emits, and it holds whatever it is accumulating for the life of the job. | remedy | what it does | what it costs | |---|---|---| | stated maximum extent | cuts the group at a ceiling and opens a new one | a long visit is reported as two, so consumers must be able to stitch | | shorter quiet period | closes groups sooner for everyone | splits genuine visits that contained a natural pause | | separate handling for known machine keys | keeps the shape honest for humans | needs a reliable way to classify a key | The first is the standard answer, and the reason to state it explicitly is that it converts an open-ended extent into a bounded one, which is what makes anything downstream plannable. What the open group costs in memory, and how that cost scales with the number of open keys, is a neighbouring subject; say that it is bounded by the ceiling, and leave the arithmetic to whoever owns it. ## What the shape does not decide Declaring a group finished is not the same as emitting it: when the value goes downstream, and whether it may go more than once, is a separate decision that can be attached to any of the three shapes. So is which moment the boundary reads — the one the pipeline assigned from the record, or the one the worker observed; a grouping that never assigned a moment is quietly grouping by arrival, and for this shape that means the quiet period is measured against the worker's own clock.
- How should a report compare two gap-closed groups whose extents differ by an order of magnitude?Carry the extent with each result and compare like with like. Totals can be compared directly, but anything per unit of time has to be divided by that group's own extent, and even then a nine-second group is a noisy estimate. Where a fixed grid is required, re-bucket the groups by their start moment rather than pretending they are equal.
- What does a maximum extent change about the meaning of the output?It changes the unit. Without it a result means one uninterrupted stretch of activity; with it a result means one stretch of activity up to the ceiling, so a long visit arrives as several rows. Consumers that count visits will over-count unless they stitch consecutive rows for the same key, and that stitching rule has to be stated, not assumed.
- Is the quiet period measured from the last arrival or from the group's start?From the last record for that key. Every arrival pushes the deadline out by the full quiet period, which is exactly why the total extent is unbounded in principle: the deadline can be pushed indefinitely. Measuring from the start would make the shape an equal span with extra steps.
saying these in an interview costs you the question
- Thinks the quiet period is the group's length
- Assumes every group for a key has the same extent
- Divides a count by a fixed interval to get a rate
- Believes a group must close eventually without any ceiling
- Never considers that a later record can bridge two groups