Paytm: Predict commit vs rollback when @Transactional methods call each other
Problem. You are shown a Spring service. placeOrder() is annotated @Transactional and calls saveOrder() on the same class, which is also @Transactional. It then calls sendNotification(), which has no annotation and throws a RuntimeException. Explain exactly what happens: what is committed, what is rolled back, and why.
Points the interviewer wanted discussed.
- Where the transaction boundaries really are
- Spring's proxy-based AOP, and why a call from one method to another in the same class (self-invocation) skips the proxy
- Whether the annotation on
saveOrder()has any effect when it is called internally - Default rollback rules for unchecked exceptions
- How propagation decides what survives
Context. This came in the first round of a backend SDE-3 loop, together with a subset-sum problem: given positive integers and a target, print any subset that adds up to the target, or report that none exists (for example, [3, 34, 4, 12, 5, 2] with target 9 gives {4, 5}).
Comments 0
No comments yet. Ask the author something, or add what happened in your own round.