aicodinginterview Waitlist

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

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

Want to know what real rounds look like first? Read the candidate reports by company.