Practice assignment

Payment webhook take-home task

A payment provider notifies your service about settled payments through signed webhooks. It retries on every non-2xx and on timeouts, and sometimes delivers the same event several times in parallel. Storage is a given Database that is async and optimistic — treat it like PostgreSQL shared by several instances.

The starter

assignment/
├── README.md
├── package.json
├── src/
│   ├── app.ts
│   ├── signature.ts TODO
│   ├── processor.ts TODO
│   └── db.ts
└── test/
    ├── webhooks.test.ts
    └── webhooks.hardening.test.ts

Requirements

  1. POST /webhooks/payments with header Webhook-Signature: t=<unix seconds>,v1=<hex>. v1 is HMAC-SHA256 over "<t>." + raw body. Verify the exact raw bytes, in constant time, accept any matching v1, and reject timestamps more than 300 s from the injected clock → 401 INVALID_SIGNATURE.
  2. A valid event is {id, type, accountId, amountMinor, currency, occurredAt} (amountMinor in integer cents). Respond 200 with APPLIED, DEAD_LETTERED or DUPLICATE.
  3. Idempotent by event id, including concurrent deliveries and two app instances: exactly one apply, everyone else DUPLICATE.
  4. payment.credited adds, payment.debited subtracts; the balance never goes negative. Dead-letter reasons, in order: UNKNOWN_TYPE, INVALID_AMOUNT, UNKNOWN_ACCOUNT, CURRENCY_MISMATCH, INSUFFICIENT_FUNDS.
  5. One transaction for an applied event: balance + processed-event row + outbox message balance-changed. Commit conflicts are retried, not returned as a lost race.

Grading rubric

AreaPoints
Correctness (provided tests including concurrency)30
Idempotency & transactional boundaries (one transaction, outbox)20
Concurrency (conflict retries, multi-instance safe)10
Webhook security (raw-body HMAC, constant-time compare, replay window)10
Own tests (concurrent duplicates, failure injection)15
TypeScript quality5
NOTES.md: outbox relay, ordering, retries vs dead-letter, ack timing10

Levels: junior ≥ 60, mid ≥ 75, senior ≥ 85 (and a strong NOTES.md).

What reviewers look for

Common mistakes

How to run it

Node.js 20+. npm ci, then npm test. Set WEBHOOK_SECRET and run npm run build && npm start to serve on port 3000. The free sample ZIP on this page is this starter.

Download this starter with no account, or generate a similar task from a payments job ad.

Download the webhooks sample ZIP Generate one from a job ad

Related practice tasks

Frequently asked questions

Is this Stripe's real webhook challenge?
No. It is an original practice task in the same problem space (signed webhooks, at-least-once delivery, an outbox). It is not a company's hiring assignment.
Why do the tests inject commit failures?
To check that a failed commit leaves no partial apply, and that a retry is safe. That is the difference between a demo handler and a payment handler.
Can I use a real database?
Yes, if you keep the HTTP contract. The provided tests use the in-memory Database. NOTES.md should describe the PostgreSQL unique index and transaction.

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.