01 · Making changes
Only product logic.
Working at any scale.
You decide how a feature should work. Fluxzero keeps its rules intact when many customers act at once. The same logic continues to work as usage grows, without engineering work for your agent.
You write
Let's build a ticketing system for concerts. Make sure the same ticket can't be booked twice, even when lots of customers book at once.
data class ReserveTicket(
@NotNull val reservationId: ReservationId,
@NotNull val ticketId: TicketId
) {
@AssertLegal
fun assertAvailable(ticket: Ticket) {
if (ticket.status != AVAILABLE) {
throw TicketErrors.notAvailable
}
}
@Apply
fun reserve(ticket: Ticket) =
ticket.copy(status = RESERVED)
@Apply
fun createReservation(user: User) =
Reservation.awaitingPayment(
reservationId, ticketId, user.id())
} record ReserveTicket(
@NotNull ReservationId reservationId,
@NotNull TicketId ticketId) {
@AssertLegal
void assertAvailable(Ticket ticket) {
if (ticket.status() != AVAILABLE) {
throw TicketErrors.notAvailable;
}
}
@Apply
Ticket reserve(Ticket ticket) {
return ticket.withStatus(RESERVED);
}
@Apply
Reservation createReservation(User user) {
return Reservation.awaitingPayment(
reservationId, ticketId, user.id());
}
} - State loads automatically
- Fluxzero provides the product state and which customer is making the change.
- Everything changes together
- If something changes while the rule runs, it runs again before the changes are saved.
- Many people, one safe result
- Each decision is kept correct even when many customers act at once.