Practice assignment
Payment webhook take-home task
- Node.js 20
- TypeScript
- Express
- HMAC signatures
- 3–4 hours
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
POST /webhooks/paymentswith headerWebhook-Signature: t=<unix seconds>,v1=<hex>.v1is HMAC-SHA256 over"<t>." + raw body. Verify the exact raw bytes, in constant time, accept any matchingv1, and reject timestamps more than 300 s from the injected clock →401 INVALID_SIGNATURE.- A valid event is
{id, type, accountId, amountMinor, currency, occurredAt}(amountMinorin integer cents). Respond200withAPPLIED,DEAD_LETTEREDorDUPLICATE. - Idempotent by event id, including concurrent deliveries and two app instances: exactly one apply, everyone else
DUPLICATE. payment.creditedadds,payment.debitedsubtracts; the balance never goes negative. Dead-letter reasons, in order:UNKNOWN_TYPE,INVALID_AMOUNT,UNKNOWN_ACCOUNT,CURRENCY_MISMATCH,INSUFFICIENT_FUNDS.- 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
| Area | Points |
|---|---|
| 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 quality | 5 |
| NOTES.md: outbox relay, ordering, retries vs dead-letter, ack timing | 10 |
Levels: junior ≥ 60, mid ≥ 75, senior ≥ 85 (and a strong NOTES.md).
What reviewers look for
- The HMAC runs on the raw bytes, not on
JSON.stringify(parsed). - Apply, processed-event and outbox commit together. A crash mid-way must not credit twice.
- No in-process lock. A second
createApp({ db })has to be safe. - NOTES.md that explains how the outbox would be relayed, when to ack the provider, and what
SELECT … FOR UPDATEor a unique index looks like in PostgreSQL.
Common mistakes
- Verifying the signature after
express.json()has already parsed the body. - Using
===on hex strings instead oftimingSafeEqual. - Returning
500on a version conflict instead of retrying, which makes the provider stampede. - Dead-lettering without recording the event, so a retry applies it later — or applying a debit and dead-lettering in the same breath.
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 adRelated 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.