Practice assignment
Sales reporting take-home (Spring Data JPA)
- Java 21
- Spring Data JPA
- Pagination
- 3 hours
Finance wants a revenue report and a paginated sales list without loading the whole table into memory. A JPQL aggregation is sketched in SaleRepository — you may use, improve or replace it. Work in ReportService.
The starter
GET /api/reports/revenue-by-category?from=YYYY-MM-DD&to=YYYY-MM-DD
GET /api/sales?region=EE&page=0&size=20
→ {content, totalElements, totalPages, page}
Requirements
- Revenue + count per category in the inclusive date range, sorted by revenue descending, 2 decimals. Aggregate in the database.
from == tois valid;from > tois400. - Paginated sales, newest
soldOnfirst, tie-break onidascending.size1–100, otherwise400.
Grading rubric
| Area | Points |
|---|---|
| Correctness (provided tests) | 30 |
| Aggregation done in the DB, no N+1 / full-table load | 20 |
| Pagination & sorting correctness, limits | 10 |
| Own tests (edge dates, empty ranges) | 15 |
| Indexes / query plan discussion | 10 |
| Structure & naming | 5 |
| NOTES.md (Postgres vs H2, indexes, caching) | 10 |
Levels: junior ≥ 60, mid ≥ 75, senior ≥ 85 (and a strong NOTES.md).
What reviewers look for
- A
GROUP BYin the database, not afindAlland a Java stream. - A stable sort (timestamp is not unique).
- NOTES.md that does not pretend H2 is Postgres: indexes you would add,
numericvs float, date/timezone, and why you did or did not cache the report.
Common mistakes
- Loading the range into memory “just this once”.
- Pages that shuffle because two sales share a
soldOn. - Off-by-one date windows (exclusive
to, or a timestamp in the wrong zone). - An unbounded
size.
How to run it
mvn verify. The provided tests use H2; a senior NOTES.md talks about the Postgres plan anyway.
Generate a reporting-style assignment from a job posting, or try the CSV import sample if you want a related operations task.
Download the import sample Generate one from a job adRelated practice tasks
Frequently asked questions
- Is this a data-science take-home?
- No. It is a backend reporting API: JPQL or SQL, pagination, and a discussion of indexes.
- Can I write a native Postgres query?
- Yes if you keep the HTTP contract. The tests run on H2, so a Postgres-only query will need a Testcontainers suite of your own, or you stay with portable JPQL and discuss Postgres in NOTES.md.
- Should I cache the report?
- Only with a short TTL and a clear invalidation story. A stale financial report is worse than a slightly slower query. Say what you would do; do not quietly cache for the timebox unless you have tests for 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.