The interview problem
Join checkout-start events with payment-result events by tenant and checkout ID. A payment result qualifies when its event timestamp is between the checkout timestamp and ten minutes afterward, including both endpoints. Inputs can arrive out of order or be retried. Show provisional unmatched checkouts, then correct them when delayed evidence arrives. Process 20,000 checkout events and 30,000 payment events per second without keeping all history in the online join.
Original system-design practice, not a reported company interview. Workload, examples and calculations are hypothetical. Apache Flink 2.3 documentation was consulted for technical context on September 27, 2026.
1. Specify the result before selecting an operator
Each immutable event carries an event ID, tenant ID, checkout ID, event timestamp, schema version and source position. A transport retry preserves the event ID. A changed payment status or refund is a new business event, not a retry duplicate.
key(a) = key(b) = (tenant_id, checkout_id) a.time ≤ b.time ≤ a.time + 10 minutes
For this exercise, emit every qualifying pair of distinct input events. This is not a nearest-payment join or a latest-status projection. If a key has several checkout events and several results, multiple pairs can qualify. A product that requires one result per checkout must define selection and replacement rules separately.
Event time describes when the business event occurred. Processing time describes when this service handles it. A payment can arrive before its checkout event without having an earlier business timestamp. Conversely, a result with an event timestamp before the checkout does not qualify under this predicate even if it arrives afterward.
Maintain a status per checkout event, identified by tenant and checkout event ID. It is matched when at least one qualifying pair is known. Unmatched is provisional within a correction horizon: accept corrections until 24 hours after that checkout's ten-minute matching interval ends. Measure eligibility using trusted durable-ingress time, not the time a delayed correction worker finishes. Events accepted before the deadline must still be processed afterward. This horizon is an explicit product policy, not proof that no later evidence exists.
2. Separate the online join from historical correction
durable checkout log ─┐
├→ validate timestamps → deduplicate
durable payment log ┘ ↓
partition by shared business key
↓
indexed online join state
↙ ↘
stable pair records checkout status
late events → durable correction queue → history lookup
↓
same pair and status outputsKeep per-key indexes ordered by event time on both sides. On a new event, search the opposite side's eligible interval, emit qualifying pairs and retain the new event until it can no longer match admitted online inputs. Archive inputs independently of online eviction so a late correction can reconstruct the relevant interval.
Store the join-policy version with outputs and historical jobs. A predicate change is a new computation, not an unexplained mutation of previously produced results. Keep tenant boundaries in every lookup and output key.
The documented Flink DataStream interval join is an event-time inner join. The provisional unmatched view and history-backed correction path proposed here are additional application behavior; they should not be presented as automatic features of that operator.
3. Derive retention from the time predicate
For a checkout a, an eligible payment has a timestamp no later than a.time + 10 minutes. Once payment-side progress has passed that boundary, no further payment admitted as on-time should match it. For a payment b, rearranging the predicate gives:
b.time − 10 minutes ≤ a.time ≤ b.time
Therefore a payment only needs to wait until checkout-side progress has passed b.time to exclude further on-time matches. The two sides have different retention needs.
Let Wₐ and Wᵦ be the relevant input watermarks and use the conservative combined progress W = min(Wₐ, Wᵦ). Sufficient online eviction conditions for this design are:
checkout a: W > a.time + 10 minutes payment b: W > b.time
Strict inequality makes the inclusive endpoint policy explicit. Map it carefully to the engine's timer resolution and watermark semantics. Events beyond the accepted progress boundary go to correction rather than being silently treated as impossible.
A watermark is a progress signal under a source policy. If it is estimated from observed timestamps and a delay allowance, it is not a physical guarantee that no older event can ever arrive. The completeness claim is limited to admitted data and the stated late-data policy.
A processing-time TTL can protect resources during an incident, but expiring state that still has possible matches sacrifices online completeness. Record that as a degraded policy and reconcile from history; do not describe arbitrary TTL eviction as a consequence of the event-time predicate.
4. Walk through an out-of-order match and a correction
Checkout A has event time 12:00 and arrives at 12:00:05. Payment B has event time 12:08 but arrives at processing time 12:14. Assume both relevant input watermarks are still 12:07 immediately before B arrives. This is an admitted out-of-order event: B is later than progress, and its timestamp lies in A's matching interval.
Emit the pair (A, B). A repeated delivery with B's event ID produces no additional logical pair. The unusually delayed progress in this trace is separate from the normal two-minute progress-lag assumption used for capacity estimates below.
Now consider another checkout C at event time 12:00. No match is known when combined progress reaches 12:11. Its interval has closed for online processing. Emit status unmatched_online, version 1, and remove its hot join state after preserving the evidence needed for historical lookup.
At processing time 12:20, payment D arrives with event time 12:09. Progress has already passed 12:11, so D is late for this online policy. The correction worker retrieves C from history, verifies the same predicate and writes pair (C, D). It replaces C's status with matched, version 2.
before correction: 100 checkouts = 70 matched + 30 unmatched after correction: 100 checkouts = 71 matched + 29 unmatched
Appending an extra matched count without removing the provisional unmatched contribution would incorrectly produce 101 checkouts. Consumers need keyed upserts or explicit retractions. Pair counts and matched-checkout counts are different metrics when one checkout has several matching results.
If D arrives after C's correction deadline, preserve the out-of-policy evidence and apply the agreed offline reconciliation process. A status finalized under a deadline means final under that policy, not proof that a real-world payment never happened.
5. Give corrections stable identity and ordering
Use a deterministic pair key such as (tenant, checkout event ID, payment event ID, join-policy version). Replaying the same pair is an idempotent upsert. A status key identifies one checkout event and policy version; business checkout ID alone is insufficient if multiple distinct checkout events are admitted.
Serialize status changes for a checkout or use a transactional compare-and-set transition. A delayed unmatched write must not overwrite an already matched state. For immutable inputs and this fixed predicate, discovering additional pairs is monotone; a matched state need not revert to unmatched. If deletions or event corrections are allowed, introduce explicit retractions and a new state model.
Write the pair and its status consequence transactionally where possible, or use an outbox with a repairable projection. Independently writing two stores can leave a pair visible while the dashboard still says unmatched after a crash. Track and reconcile such partial progress.
Late arrivals on either side require historical lookup. A very late checkout may have matching payment events that have already left hot state. The correction index must support both directions, using the same business key and time predicate. A lookup against a lagging archive is not evidence of absence. Wait for an archive ingestion frontier covering the relevant accepted source positions, or retain a durable retry and reconciliation task. Do not finalize an unmatched status or delete its evidence while an eligible correction remains pending.
6. Size hot state, stalled state and history separately
For a normal operating estimate, assume event timestamps are close to wall clock and combined progress lags by at most two minutes. Assume no additional online grace and the asymmetric retention policy above. Budget up to twelve minutes of checkout residence and two minutes of payment residence. These are operating assumptions, not universal watermark guarantees.
| Input | Rate | Residence budget | Records | Payload state |
|---|---|---|---|---|
| Checkout | 20,000/s | 720 s | 14.4 million | 3.456 GB at 240 bytes/event |
| Payment | 30,000/s | 120 s | 3.6 million | 0.720 GB at 200 bytes/event |
raw hot state = 3.456 + 0.720 = 4.176 GB with hypothetical 2.5× index/serialization allowance = 10.44 GB
These are decimal units for one full logical state copy. Measure actual overhead; the allowance excludes checkpoint retention, deduplication indexes, archive indexes, replication and output storage.
If the combined watermark stalls for 30 minutes while both inputs continue at their stated rates and incoming records require retention, additional raw state is:
checkout growth = 20,000 × 1,800 × 240 = 8.64 GB payment growth = 30,000 × 1,800 × 200 = 10.80 GB total additional raw state = 19.44 GB additional state at the same 2.5× allowance = 48.60 GB
This is incremental growth, not the final total. Backpressure or source alignment can reduce it by slowing consumption, at the cost of freshness and source backlog. Event-time retention does not imply bounded wall-clock storage when progress stops.
Raw input volume over one day is:
(20,000 × 240 + 30,000 × 200) × 86,400 = 933.12 GB/day
The correction archive therefore has a much larger footprint than the hot join. Because the correction deadline is 24 hours after the matching interval ends, retention must also cover the ten-minute interval, accepted input delay and correction processing time. Deletion should follow per-event eligibility and completed reconciliation, not a blanket 24-hour wall-clock TTL. Add indexes, safety margin and replication separately.
7. Treat slow and idle inputs explicitly
Flink's two-input operator progress follows the minimum of its input watermarks. An idle partition can hold back progress unless it is excluded through an idleness policy. Exclusion allows other inputs to advance, but old records from a resumed partition may then need the late path.
Watermark alignment can slow fast sources that otherwise force downstream state growth while waiting for slower inputs. Its availability depends on the source implementation. Do not assume that enabling a generic setting bounds every connector or every source backlog.
If all sources become idle, a timer based only on advancing event time may never fire. Define a source completion or heartbeat contract, or publish a separately labeled processing-time timeout. Wall-clock passage alone cannot prove that all earlier business events have arrived.
Validate implausible future timestamps before they influence progress estimation. A device clock far in the future can cause valid subsequent records to look late. Quarantine malformed events with their original source evidence rather than silently rewriting their business timestamps.
8. Handle replay and join amplification
Restore source positions and join state consistently after a crash. Checkpointed computation alone does not guarantee exactly-once external effects: the sink must support the required transaction or idempotency contract. Deterministic pair identities and guarded status transitions make retries recoverable, but they do not eliminate every cross-store failure automatically.
Deduplication also needs a retention contract. An event ID forgotten by the online dedup index can reappear during source replay. The persistent pair key should still prevent duplicate logical output within its promised retention period. Reject or investigate conflicting payloads under the same supposedly immutable event ID.
A hot business key with 100 checkout events and 200 payment events can yield 20,000 pairs if every pair satisfies the interval. Bounded input residence does not bound output amplification to one result per input.
Partitioning by tenant alone concentrates large customers. Partitioning by random event ID distributes load but separates matching records. Use the shared business key, investigate unexpected multiplicity and define an explicit policy for pathological keys. A limit that drops records changes completeness; surface it and retain data for repair.
Monitor progress lag per input, idle and stalled partitions, state bytes, hot keys, pair amplification, late-event fraction, correction backlog and age, duplicate conflicts and unresolved statuses. A low average processing latency can coexist with an indefinitely stalled subset of keys.
Follow-ups and self-review rubric
Follow-ups: How does retention change if payments may precede checkout time by two minutes? Which results need replacement if the product selects only the nearest payment? What happens when event timestamps are corrected? Can a late checkout be joined after all payments have left hot state? How are results repaired after an emergency TTL eviction?
A strong answer defines the interval, multiplicity and event identities, derives both retention boundaries and distinguishes event time from arrival order. It corrects unmatched results without inflating counts. An excellent answer sizes stalls and historical storage, handles resumed idle inputs and replay, and limits its completeness claim to the documented admission and correction policies.
Sources and attribution
- Apache Flink 2.3: Joining — interval predicates, inclusive bounds and the event-time inner-join operator.
- Apache Flink 2.3: Generating Watermarks — input progress, idleness and alignment.
Retrieved September 27, 2026; page publication dates unstated. The application architecture, correction protocol, event traces and capacity calculations are original practice. The custom unmatched and historical correction behavior is not attributed to the built-in interval-join API. No company interview attribution is claimed.
Continue your preparation
Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.