Inventory reservations: AI coding interview practice
You’re on the checkout team of an online shop. When a shopper starts paying, this service reserves the stock; the reservation then expires, is released, or is confirmed and shipped. Three tickets are waiting for you.
Download the project (zip, 9 KB)
Java 17, Maven, JUnit 5. Covers state transitions, all-or-nothing updates, expiry, replacing a scan with a running total.
What's inside
pom.xml README.md src/main/java/practice/inventory/Clock.java src/main/java/practice/inventory/InsufficientStockException.java src/main/java/practice/inventory/Reservation.java src/main/java/practice/inventory/ReservationService.java src/main/java/practice/inventory/StockLedger.java src/test/java/practice/inventory/BaselineTest.java src/test/java/practice/inventory/FakeClock.java src/test/java/practice/inventory/Phase1Test.java src/test/java/practice/inventory/Phase2Test.java src/test/java/practice/inventory/Phase3Test.java
Run it
mvn -q test # phase tests fail until you solve them mvn -q test -Dtest=BaselineTest # what already works; keep it green
How to practise
- Set a 60-minute timer: about 10 minutes for phase 1, 25 for phase 2, 20 for phase 3 and 5 to review.
- Use an AI chat that can read the project files (or paste them in), but type every change yourself. Many AI-enabled rounds work this way: the AI explains and suggests, you edit.
- Say your plan out loud before you prompt, and check every AI answer against the code and the tests before you trust it.
- Run only the phase you’re on, then the whole suite, so you know you didn’t break what already worked.
The three tickets
Phase 1: Fix the bug
The warehouse team says that after a busy day the site shows items as sold out while the shelves are still full. Find the cause and fix it.
Check with mvn -q test -Dtest=Phase1Test
Hint
Follow one reservation through its whole life. After confirm(), where do its units get counted, and how many times?
Phase 2: Add the feature
Carts hold several items. Implement ReservationService.reserveAll(cart, ttl): reserve every line or none, name the short SKU in the error, and reject empty carts and zero quantities.
Check with mvn -q test -Dtest=Phase2Test
Hint
Check every line before you change anything. Ask the AI what could leave half a cart reserved.
Phase 3: Make it fast
During a sale, product pages call available() on every view and the service falls over. Make available() fast without changing what it returns, including for expired and released reservations.
Check with mvn -q test -Dtest=Phase3Test
Hint
available() walks every reservation on every call. What could you keep up to date as reservations come and go instead? Expiry is the tricky part.
More practice projects
- Log insights: An on-call dashboard that reads gateway access logs. Fix a parsing bug, add an error-rate panel, then make refreshes fast with a day of traffic loaded.
- Rate limiter: A per-key token-bucket rate limiter for an API gateway. Fix a refill bug, add per-customer limits, then make it survive 200,000 keys.
Want to know what real rounds look like first? Read the candidate reports by company.