Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
An incremental load reads what is new since last time. The obvious rule — strictly after the stored watermark — silently skips every row that arrived late, and the rows it skips are gone for good because the watermark has already moved past them.
Write select_for_load(rows, state, replay_minutes). Return what to load, what was skipped, and the watermark to store for next time.
Function to write
select_for_load(rows: list[dict], state: dict, replay_minutes: int) -> dictA dict with the `selected` ids, the number `skipped`, and the new `watermark`.
How to approach it
Work out what the strictly-greater rule does to a row stamped before it.
Sample cases
+ 2 held back until you submit
a late row inside the replay window
Row b arrived late and sits before the watermark; the replay window is what catches it.
Input
Argument 1
| id | at |
|---|---|
| a | 2026-09-01T10:00:00Z |
| b | 2026-09-01T09:50:00Z |
| c | 2026-09-01T08:00:00Z |
Argument 2
{
'watermark': '2026-09-01T09:55:00Z',
'loaded_ids': [
'a'
]
}Argument 3
10Returns
{
'selected': [
'b'
],
'skipped': 2,
'watermark': '2026-09-01T10:00:00+00:00'
}the very first run
No watermark means take everything, and the new watermark is the highest event time seen.
Input
Argument 1
| id | at |
|---|---|
| a | 2026-09-01T10:00:00Z |
| b | 2026-09-01T09:50:00Z |
| c | 2026-09-01T08:00:00Z |
Argument 2
{}Argument 3
10Returns
{
'selected': [
'c',
'b',
'a'
],
'skipped': 0,
'watermark': '2026-09-01T10:00:00+00:00'
}nothing new arrived
An empty batch selects nothing and leaves the watermark exactly where it was.
Input
Argument 1
[] (empty list)
Argument 2
{
'watermark': '2026-09-01T09:55:00Z'
}Argument 3
10Returns
{
'selected': [],
'skipped': 0,
'watermark': '2026-09-01T09:55:00+00:00'
}Constraints
{'selected': [<ids>], 'skipped': <count>, 'watermark': <ISO string or None>}.datetime.fromisoformat, accepting a trailing Z.watermark - replay_minutes. Rows before that floor are skipped.state['loaded_ids']. The replay window re-reads rows on purpose; the dedupe is what stops them being loaded twice.Worked example
The stored watermark is 2026-09-01T09:55:00Z and row a at 10:00 has already been loaded. Row b arrived late, stamped 09:50 — before the watermark.
With a ten-minute replay window the floor drops to 09:45, so b is selected and a is skipped as already loaded. With no window, b is skipped and never comes back: the watermark is past it, and nothing in the pipeline will ever look there again. That single row is what the whole replay-window idea exists for.
What this tests
That incrementality is three decisions and not one — where to start reading, how far back to overlap, and how to avoid loading the overlap twice — and that advancing the watermark is a separate question from selecting rows.
select_for_load(rows: list[dict], state: dict, replay_minutes: int) -> dictSubmit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.