Practice assignment
Idempotent payment event-processing take-home
- Java 21
- Spring Boot
- Idempotency
- Outbox
- 3–4 hours
Payment events arrive from a message broker with at-least-once delivery. Balances must never be applied twice. You implement PaymentEventHandler.handle(PaymentEvent) → APPLIED | DUPLICATE | DEAD_LETTERED.
The starter
handle(event) → APPLIED | DUPLICATE | DEAD_LETTERED
CREDIT adds, DEBIT subtracts, balance never negative.
On success: OutboxMessage("balance-changed", …) in the same transaction.
Requirements
- Idempotent by
eventId, including events that were previously dead-lettered, and including concurrent redelivery. A delivery that loses a race may throw (so the broker retries) rather than apply twice. - Dead-letter reasons:
UNKNOWN_ACCOUNT,INVALID_AMOUNT,UNKNOWN_TYPE,INSUFFICIENT_FUNDS— no balance or outbox side effects. - A debit of the exact remaining balance is allowed; zero or negative amounts are
INVALID_AMOUNT. - On success, write the outbox row in the same transaction as the balance update and the processed-event record.
Grading rubric
| Area | Points |
|---|---|
| Correctness (provided tests) | 30 |
| Idempotency & transactional boundaries | 20 |
| Concurrency (optimistic locking via @Version) | 10 |
| Own tests (concurrent duplicates) | 15 |
| Structure & domain clarity | 5 |
| NOTES.md: outbox relay, ordering, retries vs DLQ | 20 |
Levels: junior ≥ 60, mid ≥ 75, senior ≥ 85 (and a strong NOTES.md).
What reviewers look for
- One transaction for apply + processed-event + outbox.
- A unique
eventIdas the source of truth, not a cache in the handler. - NOTES.md that is actually about relay (poll vs CDC), per-account ordering, and when to dead-letter versus park and retry. This rubric gives NOTES 20 points.
Common mistakes
- Writing the outbox after the transaction commits — a crash loses the message, or a retry double-notifies if you also wrote it earlier.
- Not recording dead-lettered ids, so a retry takes a different path.
- A JVM lock around the handler.
- Reordering a debit and a credit inside the handler to “be helpful”.
How to run it
mvn verify. Pair this with the Node webhook task if you want the same ideas at the HTTP edge.
Generate a practice consumer from a payments or platform job ad, or try the Node webhook sample first.
Download the webhook sample Generate one from a job adRelated practice tasks
Frequently asked questions
- How is this different from the webhook take-home?
- This one is a broker consumer in Spring Boot (you implement a handler). The webhook task is an HTTP endpoint with a signature check in TypeScript. The idempotency and outbox ideas are the same family.
- Should a lost race return DUPLICATE?
- Only if you already know the event is stored. If the transaction did not commit, throwing and letting the broker retry is correct; the retry should then see DUPLICATE.
- Do I have to build the outbox publisher?
- No. Write the row in the same transaction. Explain in NOTES.md how a relay would publish it.
Practice only. This is an original HireCheck practice assignment, not a real employer's take-home, and it is not affiliated with any company mentioned as a role example.