Practice assignment
Fintech backend take-home (ledger / holds)
- Java 21
- Spring Boot 3
- PostgreSQL
- Testcontainers
- 4 hours
A payments team needs a service that places holds on account funds before a card or transfer payment is settled. Two requests must never reserve the same money twice, and clients retry on timeouts. The app runs on PostgreSQL; schema is owned by Flyway; integration tests use Testcontainers (Docker required).
The starter
assignment/ ├── pom.xml ├── src/main/java/com/example/holds/ │ ├── HoldService.java TODO │ ├── HoldController.java │ └── Model.java ├── src/main/resources/db/migration/ │ └── V1__schema.sql └── src/test/java/com/example/holds/ ├── HoldsIntegrationTest.java ├── HoldsHardeningIntegrationTest.java └── HoldsCaptureRaceStrictTest.java
Requirements
GET /api/accounts/{id}→{id, balance, reserved, available}whereavailable = balance - reserved.POST /api/accounts/{id}/holds {reference, amount}— amount > 0, max 2 decimals;409 INSUFFICIENT_FUNDSif available is too small;201with anACTIVEhold. Idempotent byreference(unique across accounts): same reference + account + amount →200with the existing hold; any other reuse →409 REFERENCE_CONFLICT.- Concurrency-safe in the database, not with a JVM lock. Several instances share one PostgreSQL. Increasing
reservedand inserting the hold is one transaction. POST /api/holds/{id}/captureand/release— onlyACTIVEholds move; the rest are409 INVALID_HOLD_STATE. Parallel capture/release: exactly one succeeds, the account is debited at most once.
Grading rubric
| Area | Points |
|---|---|
| Correctness (integration tests including concurrency) | 30 |
| Concurrency & transaction design (locking, retries, isolation) | 20 |
| Idempotency including concurrent retries (unique constraint) | 10 |
| Own tests (Testcontainers; races, rollback) | 15 |
| Schema & migrations (constraints, indexes, money as numeric) | 10 |
| NOTES.md: optimistic vs pessimistic, expiry of stale holds, outbox | 15 |
Levels: junior ≥ 60, mid ≥ 75, senior ≥ 85 (and a strong NOTES.md).
What reviewers look for
- Whether a unique constraint on
referenceis part of the design, not only a Javaif. - How capture is made exactly-once — a row lock on the hold is a common, correct answer; a bare read under READ COMMITTED is not.
- Money as
numeric, Flyway as the schema owner,ddl-auto=validate. - NOTES.md that justifies optimistic vs pessimistic locking and mentions hold expiry and an outbox.
Common mistakes
synchronizedor a static mutex. The tests new up a secondHoldServiceon the same repositories.- Storing amounts as
doubleorfloat. - Inserting the hold and updating
reservedin two transactions. - Letting two captures both see
ACTIVEand both debit the account.
How to run it
Docker must be running. mvn verify starts PostgreSQL with Testcontainers and runs the integration tests.
Generate a practice assignment from a payments or ledger job posting, or browse the other fintech-style tasks.
Generate one from a job adRelated practice tasks
Frequently asked questions
- Is this a real take-home from a payments company?
- No. It is an original practice service in a problem space you often see in fintech-style backend roles (authorisations, ledgers, retries). It is not a company's actual hiring task.
- Why Testcontainers instead of H2?
- Holds and races depend on real constraints, isolation and row locks. An in-memory stand-in will not tell you if the design is safe.
- What does senior look like here?
- Provided tests green is not enough. Senior needs a justified locking story, a unique constraint for retries, and NOTES.md on expiry and an outbox.
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.