SteelReed

Search

Search posts, questions…

5. Spring Boot

MiniWallet: one e-wallet pet project that grows with the backend roadmap

The plan for MiniWallet, the project behind the site's hands-on labs: why an e-wallet, the target architecture, six phases from plain Java to several services, an optional buy-now-pay-later phase, where WebFlux fits, and the rules for working with agents so you write the core yourself.

20 Nov 20267 min readMid

–

1. The problem

You have 20 separate demos of 200 lines each, and none had to live with an earlier decision. An interviewer asks "what if two 500,000 VND transfers run at once" and you have no real code to talk about. This is a plan: no code yet, so no measurements yet.

2. Key idea

A project that grows forces you to change code you wrote last week. A transfer is small enough to build alone, but one wrong cent shows immediately.

Phase Goal Build
0 Correct money model Money, Account, LedgerEntry, TransferService in memory
1 One service with a DB wallet-service: REST accounts, balance, transfers; Testcontainers
2 Safe under retries Idempotency-Key, outbox table, Redis cache, rate limit
3 Split services payment-service, notification-service, Kafka, top-up saga
4 Edge layer gateway (JWT, rate limit), auth-service, SSE
5 Operations Docker Compose, CI, logs, metrics, tracing, k6 load test
6 (optional) Buy now, pay later bnpl-service: credit limit, instalment schedule, collection job

2.1 Why split only in phase 3?

In phase 3 a top-up crosses two services, so you lose the shared transaction and messages can arrive twice or late. Only then do saga and outbox have a reason to exist, and the refactor becomes a story for the interview.

2.2 Where does WebFlux go?

Choice Use when Don't use when
WebFlux gateway only forwards; SSE holds long connections the service calls blocking JPA or JDBC
Spring MVC + virtual threads wallet-service, payment-service with @Transactional you need backpressure or streaming
One service phases 0–2, boundaries are still guesses you have a concrete reason to split

Calling JPA inside a WebFlux handler blocks the event loop: a few slow queries can stall the whole service.

3. In Java

A phase 6 piece: split 1,000,000 VND into 3 instalments. VND has no minor unit, so store money as whole dong (long).

JAVA
static long[] split(long total, int n) {
    long[] parts = new long[n];
    long base = total / n;                    // 333333
    for (int i = 0; i < n; i++) parts[i] = base;
    parts[n - 1] += total - base * n;         // last instalment takes the remainder
    return parts;
}
 
split(1_000_000, 3);   // [333333, 333333, 333334]
// invariant test: sum of parts == order price, for every price and every n
Buy now, pay later: a rerun collection job never charges twice

BNPL lets people buy before they have the money: the platform pays the shop, then collects in instalments. The credit limit is held with a conditional update: UPDATE credit_line SET used = used + :x WHERE credit_limit - used >= :x.

A daily job picks instalments with status = 'DUE' AND due_date <= today. For each:

  1. Call wallet-service to debit with a fixed key installment-{id}; a rerun gets the old result back.
  2. UPDATE installment SET status = 'PAID' WHERE id = ? AND status = 'DUE'; 0 rows means another run already handled it.
  3. Not enough money keeps it DUE; past the grace period it becomes OVERDUE and the late fee is its own ledger row.

A job lock (Quartz cluster, ShedLock) only reduces duplicate runs; the key and the conditional update prevent double charges. Real BNPL is lending and needs a licence and KYC; the pet project uses fake money.

4. Working with AI

Hand to AI: pom.xml, Docker Compose, the React UI, test data. Type yourself: domain logic, transaction boundaries, SQL, the test that proves a race.

Check after each lab:

  • You can close the file and rewrite TransferService on paper.
  • You ran it and looked at real tests, logs and SQL results.
  • You removed a lock or an index on purpose and saw how it breaks.
  • You can talk for 2 minutes as if answering an interviewer.
You are a senior Java backend interviewer. Below is code I wrote MYSELF
for MiniWallet and the three questions from the lab.
- Ask one question at a time and wait for my answer; push on vague answers.
- Do NOT write solutions or fix my code; point at suspicious lines.
- At the end: score each question 1–5 and name 2 things I should revise.

5. Exercises

Exercise 1: Pick between two plans

The agent proposes: (A) build the gateway, auth, wallet, payment, notification and Kafka in week one; (B) one wallet-service with PostgreSQL, split later. Pick one, give your reason, and say what would change your choice.

Solution to Exercise 1

Pick B. With A you spend weeks configuring Kafka and the gateway before a single correct transfer exists; the service boundaries are guesses, and every bug is mixed with network errors. B lets a transaction keep data consistent, and in phase 3 you see for yourself what breaks when you split.

The choice changes once there is a concrete reason to split: two teams that must deploy independently, or one part that must scale very differently from the rest.

Summary

  • One growing project teaches more than twenty separate demos.
  • A transfer pulls in transactions, locks, idempotency, outbox, cache, messaging.
  • One service first; split in phase 3 once there is a reason.
  • WebFlux for the gateway and SSE; MVC + virtual threads for transactional services.
  • Type the core yourself; the agent scaffolds and asks the hard questions.

Self-compiled notes from official documentation and hands-on practice.

Practice interview questions on this topic

All System Design questions →All Behavioral questions →

Loading comments…
Next on the roadmapRequirements analysis and data design through a hotel booking example