Branch banking software looks simple from the outside: a teller takes cash, records it, the books balance. Inside, it’s full of rules: cash limits, ATM replenishment, end-of-day balancing, and an audit trail for everything. On a teller platform for a bank in Singapore, I helped build five core Spring Boot services using Domain-Driven Design. Here’s what was worth it.
Start with the language, not the tables
The most useful DDD practice was the least technical: use the business’s words in the code. When operations staff say “vault”, “till” and “cash position”, classes and API names say the same. That made requirement discussions with BAs and QA much faster, because nobody had to translate.
Boundaries that matched how the bank works
We split services along bounded contexts instead of along database tables:
| Context | Owns |
|---|---|
| Cash management | Till and vault positions, cash movements |
| ATM management | Replenishment and balancing of ATMs |
| Audit | An append-only record of who did what, and when |
Each context owned its data. Another context could ask through an API or react to an event, but never reach into the other’s tables.
Aggregates protect the rules
An aggregate is the unit that enforces an invariant. “A till can’t go negative” lives inside the till aggregate, not in a controller or a SQL trigger. In Spring Boot that meant:
- Domain classes with behaviour (
till.withdraw(amount)), not just getters and setters. - Application services that load an aggregate, call one method and save it, all in one transaction.
- Validation of business rules in the domain layer, so it holds no matter which API calls it.
Events for everything that happens “because of” something else
When cash moves, audit needs to know, and other systems may care too. Those reactions travel as domain events over Kafka instead of direct calls. This keeps the core transaction small, and lets audit and reporting scale on their own.
Worth deciding early (I’d emphasise this even more next time):
- Event ordering per aggregate: use the aggregate ID as the Kafka key.
- Idempotent consumers: assume every event can arrive twice.
- Reliable publishing: if the database write succeeds and publishing the event fails, you need a plan. The transactional outbox pattern is the standard answer.
DDD isn’t free. It adds structure up front. But in a domain where a wrong number is a real problem, putting the rules in one obvious place paid for itself.