A service method saves an order, calls a payment API and publishes an event, all inside one @Transactional method. What is wrong?

Short answer

Remote calls inside a database transaction hold locks and connections for the duration of the call, and the payment or event cannot be rolled back with the database. Move the external call outside the transaction with an explicit state machine (PENDING), use the transactional outbox for the event, and make the payment call idempotent.

Detailed answer

Problems: long-held connections reduce throughput; if the DB commit fails after the payment succeeded, money is taken without an order; if the event is published before commit and the commit fails, consumers see a non-existent order. Correct flow: transaction 1 saves order PENDING + outbox OrderCreated; call payment with idempotency key; transaction 2 updates to PAID/FAILED + outbox event; or orchestrate via a saga.

What the interviewer expects

Understanding of transaction scope, dual-write problems and the outbox pattern.

Common mistakes to avoid

Suggesting XA/2PC across the payment API.