#170 Code Review of an Order Service

Companies:
Alfa-Bank
Themes:
SpringTransactionsCode Review

Will everything work? If so, how many transactions will be opened? If not, what must be changed to make it work?

@Service
@RequiredArgsConstructor
@Transactional
public class OrderService {

    private final BalanceService balanceService;

    public void createOrder() {
        // Various balance validation logic
        paymentOrder();
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    private void paymentOrder() {
        balanceService.chargeOff();
    }
}

@Service
@Transactional
class BalanceService {

    public void chargeOff() {
        // Logic for debiting money from the account
    }
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in