Transaction event processor: dedup, order by time, resolve final status

seniorjava · AI-on
  1. 1Restate the problem in one line
  2. 2Sketch the data model yourself
  3. 3Ask AI for a skeleton ONLY
  4. 4Ask AI for a test plan ONLY
  5. 5Implement the core logic yourself
  6. 6Run the tests — verify, don't trust
  7. 7Ask AI for edge cases you missed
  8. 8Ask AI to review your code
  9. 9Make the final judgment yourself

Problem

A stream of transaction events arrives for many homes, possibly out of order and with retries. Each Event has (eventId, homeId, ts, status). Build a Processor whose process(List<Event>) does three things: ignore duplicate eventIds (first occurrence wins), apply each home's events in TIMESTAMP order regardless of input order, and skip events whose status is not a known transaction status — recording those skipped ones. Then finalByHome() returns each home's status from its latest valid event by ts, duplicatesIgnored() returns how many duplicate-eventId events were dropped, and invalid() returns the recorded invalid events. Valid statuses: LISTED, OFFER_MADE, UNDER_CONTRACT, CLOSED, CANCELLED.

iThe deal with the pair partner

The AI is deliberately fallible — it gives hints, not solutions, and sometimes proposes wrong code. It cannot touch your editor. Paste what you choose, then Run. Anything AI-derived stays UNVERIFIED until your tests go green.

Self-check

  • dedup is by eventId with first-wins semantics, and the dropped count is reported (idempotent ingestion of retried events)
  • final status per home is decided by the maximum ts, not by input/arrival order
  • an unknown status is excluded from the final computation AND recorded in invalid(), not silently dropped
  • homes are independent — each resolves from its own events only
  • you named the time cost (group + sort per home) and what changes at scale (streaming/last-write-wins on a ts watermark instead of re-sorting a full batch)
Hints / what this doesn't test

An Opendoor-flavored ingestion problem: a noisy event stream (out-of-order arrival, retried/duplicated events, garbage statuses) has to collapse into one clean answer per home. Restate the three jobs before you code — "So I dedup by eventId first-wins, then per home I take the status from the event with the largest ts, and anything with an unknown status I skip but keep in a list?"

Why the naive starter is wrong (name the bugs out loud): it writes homeId -> status in input order, so (1) the last-seen event wins instead of the latest-by-ts event, (2) a retried eventId overwrites and is never counted, and (3) a garbage status like TELEPORTED is treated as a real terminal state. All three are the classic ingestion failures: no idempotency, no event-time ordering, no input validation.

What this problem does not test (say so): late-arriving events after a "final" read (watermarks), tie-breaking when two valid events share the exact same ts, state-transition legality (is LISTED -> CLOSED even allowed?), and durable/streaming processing. A senior names that the batch group-and-sort here becomes a per-home last-write-wins on an event-time watermark once this is a real stream rather than a list you hold in memory.

Solution.javaauto-runs ~0.8s after you pause
unverifiedEdited since last clean run — run to verify.

Tests

○ Not run yet — edit the code or press Run
  • out_of_order_resolved_by_ts
  • duplicate_eventId_ignored
  • final_status_per_home
  • invalid_recorded

Pair partner (병신 모드 · 버그 잡기)

gpt-4o-mini

Ask for a skeleton or a test plan — not the answer. Then implement the core yourself and come back for edge cases. Remember: the partner is fallible. Verify everything by running it.

The partner sees your editor but cannot change it. Copy any suggestion in by hand, then Run to verify.

AI랑 먼저 페어하고 눌러